From d82dc9a90eb96a1a5eddf1b5cc2346e0cbbe70ae Mon Sep 17 00:00:00 2001
From: Cornelius Rautenbach <cornel.rautenbach@gmail.com>
Date: Wed, 24 Nov 2021 22:44:30 +0200
Subject: [PATCH] Log changes

---
 logs/logs.go | 27 ++++++++++++++++++++++-----
 1 file changed, 22 insertions(+), 5 deletions(-)

diff --git a/logs/logs.go b/logs/logs.go
index 9252606..6282f48 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,
 		})
 	}
 }
-- 
GitLab