Using log/slog with log.Logger format?

242 views
Skip to first unread message

cpu...@gmail.com

unread,
Jul 20, 2023, 9:48:49 AM7/20/23
to golang-nuts
The log/slog logger uses the log.Logger format by default. Implementation is internal.

In a gradual switch to slog I'd like to keep that format for time being but customize other handler options- hence need to create a new Logger. Is there a good way to do that without reimplementing the entire internal slog logic around commonHandler etc?

Cheers,
Andreas

cpu...@gmail.com

unread,
Jul 22, 2023, 9:22:42 AM7/22/23
to golang-nuts
Seems it's not possible to create a logger using the log.Logger format in a straight-forward way?

Jonathan Amsterdam

unread,
Jul 29, 2023, 6:20:42 AM7/29/23
to golang-nuts
We don't plan on exposing the commonLogger implementation, but you can write your own handler to get the exact format you want.

See github.com/jba/slog/handlers for some existing code.
See https://github.com/golang/example/tree/master/slog-handler-guide for a guide to writing a slog handler.

Reply all
Reply to author
Forward
0 new messages