From 064279bb0988fc46d9b6d3be0c1ddea3f05172e6 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?France=CC=81=20Wilke?= <francewilke@gmail.com>
Date: Fri, 1 Sep 2023 15:54:59 +0200
Subject: [PATCH] Cater for body exclusion in LogRequestInfo

---
 logs/logs.go | 15 ++++++++-------
 1 file changed, 8 insertions(+), 7 deletions(-)

diff --git a/logs/logs.go b/logs/logs.go
index 89cb0f8..99aa65e 100644
--- a/logs/logs.go
+++ b/logs/logs.go
@@ -219,11 +219,14 @@ func LogShipmentID(id int64) {
 	}, "Current-shipment-ID")
 }
 
-func LogRequestInfo(req events.APIGatewayProxyRequest, extraFields ...map[string]interface{}) {
+func LogRequestInfo(req events.APIGatewayProxyRequest, shouldExcludeBody bool, extraFields map[string]interface{}) {
 	fields := map[string]interface{}{
 		"path":   req.Path,
 		"method": req.HTTPMethod,
-		"body":   req.Body,
+	}
+
+	if !shouldExcludeBody {
+		fields["body"] = req.Body
 	}
 
 	if req.QueryStringParameters != nil {
@@ -234,11 +237,9 @@ func LogRequestInfo(req events.APIGatewayProxyRequest, extraFields ...map[string
 		fields["client_version"] = req.Headers["client-version"]
 	}
 
-	if extraFields != nil {
-		for i := range extraFields {
-			for k, v := range extraFields[i] {
-				fields[k] = v
-			}
+	for k, v := range extraFields {
+		if k != "" {
+			fields[k] = v
 		}
 	}
 
-- 
GitLab