Description
I started writing a set of tests to compare the output from the zerolog
handlers I was testing. I wanted to make sure that the different tests were providing the same logging output. I found some things that seemed odd so I expanded that test to all of the other handlers as well.
- I'm finding that some of the weak and accumulated tests are writing log entries with duplicate JSON fields.
Apparently for some tests the same fields are being configured as "context" as well as data. When the BenchmarkEventCtxWeak
test runs it generates a handler via newWithCtx()
which configures the handler with the various test fields. Then the same data is added again via logEventCtxWeak()
. The result is that some handlers duplicate those fields in the output:
zerolog: no
phuslog: yes
zap: yes
zapsugar: yes
slog: yes
slogzap: yes
apex: no
logrus: no
log15: no
logf: yes
I'm not sure if adding the same fields via context and logging is intentional. In any event, some tests are writing twice as much text for half of the tests.
-
Most of the handlers use
"msg"
for the message field name but a few use"message"
. Thelog/slog
documentation shows a constantMessageKey = "msg"
so it is probably a bug in the handler code for theapex
,logf
,phuslog
, andzerolog
handlers. -
The
phuslog
handler fails JSON unmarshaling for several reasons:
- The handler inserts the
"users"
array ofuser
objects as a string representation. - The second occurrence of the
"primes"
field (see point 1 above) is likewise turned into a string. - The second occurrence of the
user
field fails to make an embedded hash object for the second instance of"user"
:
"user":,"name":"John Doe","age":23,"dob":"2000-09-09T00:00:00Z",
-
The
apex
logger wraps the attribute fields in an additional object named"fields"
. In addition to using"message"
the time is called"timestamp"
instead of thelog/slog
constantTimeKey = "time"
. -
The
log15
doesn't use the proper timestamp format (missingZ
). The log level is specified as"lvl"
instead of thelog/slog
constantLevelKey = "level"
. -
The
logf
handler doesn't generate JSON.
Some of these errors suggest bugs in the handlers and I may post them with the appropriate developers. The one that prompted me to write this ticket is the duplicate fields (point 1 above). I'd like to know what is expected (duplicate fields or not) and if the context fields should be different from the attribute fields added later. I am working on adding log/slog
handlers for zerolog
and I'd like to get them right so that I can see the performance thereof.
I'd also like to know if these new tests are of interest. If so I can create an appropriate pull request after I iron out some of these errors.