Skip to content

Commit eeeb624

Browse files
authored
Merge pull request #121 from thockin/master
funcr: Fix bug in repeated calls to WithValues
2 parents 8d00e35 + 2750c5e commit eeeb624

File tree

2 files changed

+7
-5
lines changed

2 files changed

+7
-5
lines changed

funcr/example_test.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,9 +94,10 @@ func ExampleOptions_renderHooks() {
9494
RenderValuesHook: valuesAsObject,
9595
})
9696
log = log.WithName("MyLogger")
97-
log = log.WithValues("savedKey", "savedValue")
97+
log = log.WithValues("savedKey1", "savedVal1")
98+
log = log.WithValues("savedKey2", "savedVal2")
9899
log.Info("the message", "key", "value")
99-
// Output: {"log:logger":"MyLogger","log:level":0,"log:msg":"the message","labels":{"savedKey":"savedValue"},"key":"value"}
100+
// Output: {"log:logger":"MyLogger","log:level":0,"log:msg":"the message","labels":{"savedKey1":"savedVal1","savedKey2":"savedVal2"},"key":"value"}
100101
}
101102

102103
func ExamplePseudoStruct() {

funcr/funcr.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -722,15 +722,16 @@ func (f *Formatter) AddName(name string) {
722722
func (f *Formatter) AddValues(kvList []interface{}) {
723723
// Three slice args forces a copy.
724724
n := len(f.values)
725-
vals := f.values[:n:n]
726-
vals = append(vals, kvList...)
725+
f.values = append(f.values[:n:n], kvList...)
726+
727+
vals := f.values
727728
if hook := f.opts.RenderValuesHook; hook != nil {
728729
vals = hook(f.sanitize(vals))
729730
}
730731

731732
// Pre-render values, so we don't have to do it on each Info/Error call.
732733
buf := bytes.NewBuffer(make([]byte, 0, 1024))
733-
f.values = f.flatten(buf, vals, false, true) // escape user-provided keys
734+
f.flatten(buf, vals, false, true) // escape user-provided keys
734735
f.valuesStr = buf.String()
735736
}
736737

0 commit comments

Comments
 (0)