httplog icon indicating copy to clipboard operation
httplog copied to clipboard

Fields duplicate instead of overriding

Open bqback opened this issue 1 year ago • 1 comments

I do something like httplog.LogEntrySetField(ctx, "step", step) and then oplog := httplog.LogEntry(ctx) to get the logger for that layer as the request goes through my app, with step being either "handler", "service" or "storage".

I kinda expected the method to override this field as the key name remains the same, but instead I just get step: "handler" step: "service" step: "storage" in logs.

What am I doing wrong?

~~Should I use LogEntrySetFields with a copy of the context as argument to "preserve" the original for the next layer?~~ Doesn't seem to work based on a quick test, at least without some voodoo to build a copy from scratch.

bqback avatar Jun 04 '24 16:06 bqback

This sounds like an implementation detail, could you provide more code?

rkgarcia avatar Aug 22 '24 18:08 rkgarcia

Closing since v3 was merged.

https://github.com/go-chi/httplog/pull/52

VojtechVitek avatar Jun 04 '25 18:06 VojtechVitek