-
Notifications
You must be signed in to change notification settings - Fork 81
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
negative V value gets set to 0 which limits slog level usage #335
Comments
* If sink is `*slogSink` pass add the level to the logger as is fixes go-logr#335
* If sink is `*slogSink` add the level to the logger as is fixes go-logr#335
I don't recall why the "all levels can be mapped" language was added. The reason we don't support negative V levels is because we didn't want code whose logger had been "pre-biased" to "bypass" the bias. @pohly somewhat disagrees and we have not had a real reason to resolve it. See also #258 Also, there's a philosophical mismatch here - logr holds as truth that "warning logs" are not a real thing. There are things worth logging and things not worth logging. Deciding at the logging call-site whether a log-line is "significant" assumes that you know that a priori. My own experience says otherwise, and the use of "warn" almost always becomes muddy over time. @pohly - thoughts? |
The docs say "All logr verbosity levels can be mapped" - note that it does not say that all slog levels can be mapped. As @thockin said, by design logr only supports a half-open range of verbosity levels (>= 0) whereas slog uses a range that is open both ways (negative and positive).
Code can already be abusive by using
My use case still stands: if we allowed V(-1), the caller of some code could make that code more verbose by passing |
I'm attempting to use |
Maybe we could map the V levels differently in the slog sink? For Example: func (l *slogSink) Info(level int, msg string, kvList ...interface{}) {
var slogLevel slog.Level
switch {
case level == 0:
slogLevel = slog.LevelInfo
case level == 1:
slogLevel = slog.LevelWarn
case level >= 2:
slogLevel = slog.LevelDebug
}
l.log(nil, msg, slogLevel, kvList...)
} Right this is how I'm setting up our logger: logr.FromSlogHandler(slog.NewTextHandler(os.Stdout, &slog.HandlerOptions{
Level: cfg.LogLevel,
})) With this if
Which does allow me to distinguish between different levels but isn't really intuitive. |
When using the logr API, Can we go back and look at what you are trying to achieve? If I get it right, you have code which uses the logr API and thus log levels >= 0. Do you also have code which uses the slog API? You now want to emit log entries which are "more important" than In Kubernetes, we start with 0 = "most important, always enabled". We use |
Exactly. We could map V(0) to slog Warn, V(1) to warn-1, ... V(4) to slog Info, ... V(8) to slog Debug. But then the default level for a longer.Info() would be Warning. That doesn't seem right. Life embraces the idea that there's no such thing as a warning. Just Info and Error. If anything, logger.Info() should have been logger.Log() |
docs state:
logr/README.md
Lines 196 to 197 in a64db0b
However, when passing a negative int to
V
it gets set to 0:logr/logr.go
Lines 308 to 317 in a64db0b
This makes
slog.LevelWarn
inaccessible.The text was updated successfully, but these errors were encountered: