diff --git a/logs/logs.go b/logs/logs.go index 92526061801d0b87b4b13bbe1da758507a8343df..6282f489b93518dbc1501471d56aa9238edf1eba 100644 --- a/logs/logs.go +++ b/logs/logs.go @@ -6,6 +6,7 @@ import ( "net/http" "net/url" "os" + "runtime" "strings" "github.com/MindscapeHQ/raygun4go" @@ -23,8 +24,7 @@ var build string var raygunClient *raygun4go.Client // TODO -// 1. SET JSON vs Console formatting -// 2. Sensitive word filtering +// Sensitive word filtering func InitLogs(requestID *string, isDebugBuild bool, buildVersion string, request *events.APIGatewayProxyRequest, client *raygun4go.Client) { currentRequestID = requestID @@ -33,8 +33,25 @@ func InitLogs(requestID *string, isDebugBuild bool, buildVersion string, request build = buildVersion raygunClient = client - formatter := log.JSONFormatter{} - log.SetFormatter(&formatter) + 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") @@ -49,7 +66,7 @@ func InitLogs(requestID *string, isDebugBuild bool, buildVersion string, request if requestID != nil { logger = log.WithFields(log.Fields{ - "request_id": requestID, + "request_id": *requestID, }) } }