Skip to content

Different tests log different results #2

Open
@madkins23

Description

@madkins23

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.

  1. 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.

  1. Most of the handlers use "msg" for the message field name but a few use "message". The log/slog documentation shows a constant MessageKey = "msg" so it is probably a bug in the handler code for the apex, logf, phuslog, and zerolog handlers.

  2. The phuslog handler fails JSON unmarshaling for several reasons:

  • The handler inserts the "users" array of user 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",
  1. 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 the log/slog constant TimeKey = "time".

  2. The log15 doesn't use the proper timestamp format (missing Z). The log level is specified as "lvl" instead of the log/slog constant LevelKey = "level".

  3. 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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions