go-chi / httplog

Go HTTP request logger with structured logging capabilities built on "log/slog" package
MIT License
207 stars 42 forks source link

Fields duplicate instead of overriding #46

Open bqback opened 4 months ago

bqback commented 4 months ago

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.

rkgarcia commented 2 months ago

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