Skip to content

Commit 2245671

Browse files
authored
Log context vars as strings
2 parents ba341ae + 2ee2659 commit 2245671

File tree

2 files changed

+6
-9
lines changed

2 files changed

+6
-9
lines changed

logger.go

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -472,11 +472,8 @@ func (nz *NuclioZap) addContextToVars(ctx context.Context, vars []interface{}) [
472472
continue
473473
}
474474

475-
// create a slice 2 slots larger
476-
varsWithContext := make([]interface{}, 0, len(vars)+2)
477-
varsWithContext = append(varsWithContext, key)
478-
varsWithContext = append(varsWithContext, value)
479-
vars = append(varsWithContext, vars...)
475+
// append key and value to the beginning of the vars
476+
vars = append([]interface{}{string(key), value}, vars...)
480477
}
481478

482479
return vars

logger_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -86,9 +86,9 @@ func (suite *LoggerTestSuite) TestAddContextToVars() {
8686

8787
vars := zap.addContextToVars(ctx, []interface{}{"some", "thing"})
8888
for _, expected := range []interface{}{
89-
RequestIDKey,
89+
string(RequestIDKey),
9090
requestID,
91-
ContextIDKey,
91+
string(ContextIDKey),
9292
contextID,
9393
} {
9494
suite.Require().Contains(vars, expected)
@@ -101,9 +101,9 @@ func (suite *LoggerTestSuite) TestAddContextToVars() {
101101
existingRequestID := "987654"
102102
vars = zap.addContextToVars(ctx, []interface{}{"some", "thing", "requestID", existingRequestID})
103103
for _, expected := range []interface{}{
104-
RequestIDKey,
104+
string(RequestIDKey),
105105
existingRequestID,
106-
ContextIDKey,
106+
string(ContextIDKey),
107107
contextID,
108108
} {
109109
suite.Require().Contains(vars, expected)

0 commit comments

Comments
 (0)