-
Type: Improvement
-
Resolution: Fixed
-
Priority: Unknown
-
Affects Version/s: None
-
Component/s: None
-
None
-
Fully Compatible
-
Not Needed
-
The level value returned by the Info function of a LogSink implementation will always be 1 less than the analogous options.LogLevel values.
For example, options.LogLevelInfo is set to logger.LevelInfo, which is the 1 enumeration. The internal logger "Print" method will return 0 (logger.LevelInfo - logger.DiffToInfo). In general, the internal "Print" method returns the difference between the internal level and the "DiffToInfo" constant. This is to ensure that "Info" is the 0th "level", so as to sync the LogSink with the go-logr/logr library:
Level V(0) is the default, and logger.V(0).Info() has the same meaning as logger.Info().
Here is a gist that illustrates this problem.
There are two notable solutions to this problem:
(1) offset the stable api levels:
const (
LogLevelInfo LogLevel = LogLevel(logger.LevelInfo - logger.DiffToInfo)
LogLevelDebug LogLevel = LogLevel(logger.LevelDebug - logger.DiffToInfo)
)
This would be a breaking change since users may already be offsetting these levels in custom LogSink implementations.
(2) create a function that converts the level returned by the log sink to the stable API level.