Skip to content
Snippets Groups Projects
Select Git revision
  • d82dc9a90eb96a1a5eddf1b5cc2346e0cbbe70ae
  • main default protected
  • trading_hours
  • refactor_trading_hours
  • audit_cleaning_cater_for_non_struct_fields
  • remove-info-logs
  • sl-refactor
  • 18-use-scan-for-param-values
  • 17-order-search-results
  • 4-simplify-framework-2
  • 1-http-error
  • v1.297.0
  • v1.296.0
  • v1.295.0
  • v1.294.0
  • v1.293.0
  • v1.292.0
  • v1.291.0
  • v1.290.0
  • v1.289.0
  • v1.288.0
  • v1.287.0
  • v1.286.0
  • v1.285.0
  • v1.284.0
  • v1.283.0
  • v1.282.0
  • v1.281.0
  • v1.280.0
  • v1.279.0
  • v1.278.0
31 results

logs.go

Blame
  • logs.go 5.28 KiB
    package logs
    
    import (
    	"errors"
    	"fmt"
    	"net/http"
    	"net/url"
    	"os"
    	"runtime"
    	"strings"
    
    	"github.com/MindscapeHQ/raygun4go"
    
    	"github.com/aws/aws-lambda-go/events"
    	log "github.com/sirupsen/logrus"
    )
    
    var logger *log.Entry
    
    var apiRequest *events.APIGatewayProxyRequest
    var currentRequestID *string
    var isDebug = false
    var build string
    var raygunClient *raygun4go.Client
    
    // TODO
    // Sensitive word filtering
    
    func InitLogs(requestID *string, isDebugBuild bool, buildVersion string, request *events.APIGatewayProxyRequest, client *raygun4go.Client) {
    	currentRequestID = requestID
    	apiRequest = request
    	isDebug = isDebugBuild
    	build = buildVersion
    	raygunClient = client
    
    	if isDebugBuild {
    		log.SetReportCaller(true)
    		log.SetFormatter(&log.TextFormatter{
    			ForceColors:      true,
    			PadLevelText:     true,
    			DisableTimestamp: true,
    			CallerPrettyfier: func(f *runtime.Frame) (string, string) {
    				// Exclude the caller, will rather be added as a field
    				return "", ""
    			},
    		})
    	} else {
    		log.SetReportCaller(true)
    		log.SetFormatter(&log.JSONFormatter{
    			CallerPrettyfier: func(f *runtime.Frame) (string, string) {
    				// Exclude the caller, will rather be added as a field
    				return "", ""
    			}})
    	}
    	log.SetLevel(LogLevel())
    
    	val, exists := os.LookupEnv("DEBUGGING")
    	if exists && val == "true" {
    		log.SetLevel(log.TraceLevel)
    		log.SetReportCaller(true)
    	}
    
    	logger = log.WithFields(log.Fields{
    		"environment": getEnvironment(),
    	})
    
    	if requestID != nil {
    		logger = log.WithFields(log.Fields{
    			"request_id": *requestID,
    		})