Unable to change level during execution via LevelVar
Slog handlers can use LevelVar to specify the handler logging level.
Unlike specifying a Level (which is actually an int),
a LevelVar is supposed to be changeable during program execution.
Verify:
Level Var
level not changed
SlogTest
Failure of embedded slog/slogtest
Documentation on building a handler suggests testing using slog/slogtest, part of the Go release since 1.21.
While the verification suite includes tests patterned after those in slogtest,
an additional single test invokes the slogtest testing sequence (involving multiple tests).
Since this is a separate package, all error messages are returned at once.
This is the only warning that affects TestSlogTest and all of its error messages.
If HandlerOptions.ReplaceAttr
is provided it should be honored by the handler.
However, documentation on implementing handler methods seems to suggest it is optional.
{
"level": "INFO",
"message": "This is a message",
"time": "2025-02-16T01:39:50.73380189Z"
}
Verify:
Source Key
no 'source' key
{
"level": "INFO",
"message": "This is a message",
"time": "2025-02-16T01:41:19.497315904Z"
}
Suggested
Duplicates
Duplicate field(s) found
Some handlers (e.g. slog.JSONHandler)
will output multiple occurrences of the same field name
if the logger is called with multiple instances of the same field,
generally by using WithAttrs and then the same fields in the eventual log call (e.g. Info).
This behavior is currently under debate
with no resolution at this time (2024-01-15) and a
release milestone of (currently unscheduled) Go 1.23,
(whereas Go Release 1.22
is currently expected in February 2024).
Verify:
Attribute Duplicate
map[alpha:2 charlie:3]
Verify:
Attribute With Duplicate
map[alpha:2 charlie:3]
DurationString
slog.Duration() logs a string representation instead of nanoseconds
The slog.JSONHandler uses nanoseconds for time.Duration but some other handlers use a string representation.
Verify:
Group Duration
8h3m22s
{
"group": {
"inner": "8h3m22s"
},
"level": "INFO",
"message": "This is a message",
"outer": "8h3m22s",
"time": "2025-02-16T01:41:19.49527052Z"
}