Open
Description
It appears that With
has undocumented and inconsistent behaviour around it's handling of extra parameters depending on the output format being used.
I've built a test case that showcases the behaviour for the plain
logger output:
t.Run("multiple unpaired with/plain", func(t *testing.T) {
var buf bytes.Buffer
rootLogger := New(&LoggerOptions{
Name: "with_with_test",
Output: &buf,
})
derived1 := rootLogger.With("a").With("b")
derived1.Info("test1")
output := buf.String()
dataIdx := strings.IndexByte(output, ' ')
assert.Equal(t, "[INFO] with_with_test: test1: EXTRA_VALUE_AT_END=a EXTRA_VALUE_AT_END=b\n", output[dataIdx+1:])
})
t.Run("multiple unpaired with/json", func(t *testing.T) {
var buf bytes.Buffer
rootLogger := New(&LoggerOptions{
Name: "with_with_json_test",
JSONFormat: true,
Output: &buf,
})
derived1 := rootLogger.With("a").With("b")
derived1.Info("test1")
var raw map[string]interface{}
if err := json.Unmarshal(buf.Bytes(), &raw); err != nil {
t.Fatal(err)
}
assert.Equal(t, "b", raw[MissingKey])
})
This behaviour differs between the JSON
and plain
output formats, as JSON
converts the arguments into a map (destroying multiple instances of EXTRA_VALUE_AT_END
) while plain
does not.
Metadata
Metadata
Assignees
Labels
No labels