jlewi / foyle

Foyle is a copilot to help developers deploy and operate their applications.
https://foyle.io
Apache License 2.0
111 stars 10 forks source link

logr overriding and not duplicating values #345

Open jlewi opened 5 days ago

jlewi commented 5 days ago

See: https://github.com/go-logr/logr/issues/170

If you do "WithValues" multiple times for the same field, zapr will adds the field multiple times to the record. I'm not sure that's what we want; we probably want to override the field with the latest value.

One way to deal with this would be to change how we pass "logr" along in contexts. Rather than passing along a logr with any values attached to it in context we could define a new interface

type LogR struct {
    log *LogR
    fields map[string]interface{}
}

We could then store the fields in map. We could override "WithValues" so that each time it gets called we reconstruct the logr.