You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Does this issue reproduce with the latest release?
-
What did you do?
// Handle handles the Record.// It will only be called if Enabled returns true.// Handle methods that produce output should observe the following rules:// - If r.Time is the zero time, ignore the time.// - If an Attr's key is the empty string, ignore the Attr.Handle(rRecord) error
It will only be called if Enabled returns true.
That is misleading, there is no checks for Enabled on available handlers which call directly commonHandler.handle. commonHandler.handler does not have enabled check. This check is performed by Logger call chain using Logger.logDepth where enabled is checked.
That can lead some undesired side effects; e.g.
slog.SetDefault(slog.New(slog.HandlerOptions{
Level: slog.LevelWarn,
}.NewTextHandler(os.Stdout)))
slog.Info("slog.Info: that is ignored as it should")
slog.Warn("slog.Warn: that is logged as it should", "info.enabled", slog.Default().Enabled(slog.LevelInfo))
log.Print("log.Print: did not expect to see that in logs")
slog.Default().Handler().Handle(
slog.NewRecord(
time.Now(),
slog.LevelInfo,
"call.Handle: I guess thats ok if that is printed always",
0,
nil,
))
What did you expect to see?
No info logs.
What did you see instead?
time=2022-12-19T22:13:49.033+02:00 level=WARN msg="slog.Warn: that is logged as it should" info.enabled=false
time=2022-12-19T22:13:49.033+02:00 level=INFO msg="log.Print: did not expect to see that in logs"
time=2022-12-19T22:13:49.033+02:00 level=INFO msg="call.Handle: I guess thats ok if that is printed always"
Primarly it conserns log.Output set by func SetDefault(l *Logger)
// It is used to link the default log.Logger to the default slog.Logger.func (w*handlerWriter) Write(buf []byte) (int, error) {
...r:=NewRecord(time.Now(), LevelInfo, string(buf), depth, nil)
returnorigLen, w.h.Handle(r)
}
So shouldn't this handlerWriter call have something like
What version of Go are you using (
go version
)?Does this issue reproduce with the latest release?
-
What did you do?
That is misleading, there is no checks for
Enabled
on available handlers which call directlycommonHandler.handle
. commonHandler.handler does not have enabled check. This check is performed by Logger call chain usingLogger.logDepth
where enabled is checked.That can lead some undesired side effects; e.g.
What did you expect to see?
No info logs.
What did you see instead?
Primarly it conserns
log.Output
set byfunc SetDefault(l *Logger)
So shouldn't this
handlerWriter
call have something likeor should Handle implementation do this check?
Originally posted by @mkungla in #56345 (comment)
The text was updated successfully, but these errors were encountered: