httplog
httplog copied to clipboard
Go HTTP request logger with structured logging capabilities built on "log/slog" package
`LogEntrySetFields`: Use the varargs syntax to supply the additional log arguments correctly Without the change in this changeset, running `go test` fails with: ``` ./httplog.go:361:37: slog.Logger.With arg "attrs" should be...
It is likely that an application using `slog` will want to use its own pre-configured `*slog.Logger` or provide a `slog.Handler` that a logger should be created from. The design of...
`httplog.LogEntry` should return `*slog.Logger` instead of `slog.Logger` because then, the returned value implements interfaces for the slog API. Reason is that slog’s Logger methods need pointer receivers. Note that `*slog.Logger`...
Currently, the response body will only be logged if the returned status code is >= 400. https://github.com/go-chi/httplog/blob/master/httplog.go#L90C4-L96C7. https://github.com/go-chi/httplog/blob/master/httplog.go#L146C3-L149C4. I have a use case for `httplog` to act as an audit...
When an error with level panic occurs, it does not print the stack trace. It still appears in the terminal output, but is not written in the file. ``` {"timestamp":"2023-12-09T13:56:15.436815815+02:00","level":"ERROR","message":"Response:...
Using `httplog` in combination with [chi compress middleware](https://github.com/go-chi/chi/blob/master/middleware/compress.go) logs compressed response body. Has anyone encountered similar issues before? I wrote a custom implementation of `httplog` where I manually decompress response,...
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...
Hi guys, is it possible to add a custom value from context to log, for example userID? The idea is to create custom middleware that will take userID from jwt,...
Should I put this middleware before panic? There is not much about it.
`LogEntry` returns the logger pointer stored on `RequestLoggerEntry`, therefore LogEntrySetField needs to update the value that pointer refers to, instead of replacing it with a new pointer. Added a test...