go-chi / httplog

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

use chi middleware.LogFormatter in Handler instead of zerolog logger #18

Closed jellis18 closed 1 year ago

jellis18 commented 1 year ago

currently the private requestLogger is hardcoded in the Handler. As far as I can tell this means that you cannot customize the logger request fields.

Would it be useful to have the same interface as the chi middleware logger and have the Handler take in a LogFormatter. That way a user could customize the request fields.

I'm pretty new to this package so I could be wrong but I'd be happy to make an MR with this change.

Shubhaankar-Sharma commented 1 year ago

true afaik its not possible to customise logger request fields, but imo if we use something similar to what slog did that would be better... https://pkg.go.dev/golang.org/x/exp/slog#HandlerOptions, since in my latest pr we're switching to slog, all request fields would be of the type Slog.Attr, we can call a function that we take in the config and supply it with each attribute and they can change the attribute key or customise the value...

jellis18 commented 1 year ago

@Shubhaankar-Sharma a function would work as well to let a user customize the log fields/attrs, I was just wondering if it would be better to keep the interface from the chi-logger middleware.

pkieltyka commented 1 year ago

so, indeed we are phasing out zerolog altogether in favour of "slog"

pkieltyka commented 1 year ago

v2 is out, which includes solution