Hi,

Could someone please clarify the intent of the slog.LevelVar.Set method?

Specifically is it the intent that slog.LevelVar.Set should set the logging
level regardless of the underlying handler (std or 3rd party package)?

To achieve this should all 3rd party handlers implement a "Level" field in
their HandlerOptions struct, and respect it's value if changed?

I am looking to moving our codebase over to the new slog, but we already have
logging via the uber zap logger. There is now an (experimental) bridge from
slog to uber zap [1] which would make this transition easier.

But as far as I can tell, you can't use slog to change the logging level with
this bridge to a zap based handler.

You can still change the log level but you have to drop down to zap level which
exposes the fact you are using zap. This also leaves you with two ways to
change the level, only one of which will impact the output.

I don't think was the intent or what a developer might expect.

I have tried to show this with a simple example on the playground.

https://go.dev/play/p/KSaCCzP5Fi3

The problems seems to be the current zap implementation of the
zapslog.HandlerOptions struct [2] is missing a "Level" field (of type
slog.Leveler). This seems to be what is implied by the "How to write a handler"
[3] documentation as the "Options" struct in the example does have a "Level"
filed of type "slog.Leveler". 

So, before I raise an issue on github against zap, could someone clarify what
the original intent was? 

Many thanks

Owen

[1] see: https://github.com/uber-go/zap/blob/exp/v0.2.0/exp/zapslog/handler.go
[NOTE: this is against the exp/v0.2.0 tag which is what my go tool chain
installed).
[2] see:
https://github.com/uber-go/zap/blob/87e467e9b7509962236295e116116980580ef8bc/exp/zapslog/handler.go#L42
[3] https://github.com/golang/example/blob/master/slog-handler-guide/README.md

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/85ef698122c73c9570ef06affd9fe2b6b2bf31b6.camel%40kulawe.com.

Reply via email to