Skip to content

Commit

Permalink
Replace 'Interface' usage with correct zerolog api (#1069)
Browse files Browse the repository at this point in the history
Handle structures as documented in zerolog, similar to how
zap does in it's test case.
  • Loading branch information
Emyrk authored Mar 16, 2022
1 parent 32a858e commit 34cb012
Showing 1 changed file with 24 additions and 12 deletions.
36 changes: 24 additions & 12 deletions benchmarks/zerolog_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,30 +34,42 @@ func newDisabledZerolog() zerolog.Logger {
return newZerolog().Level(zerolog.Disabled)
}

func (u *user) MarshalZerologObject(e *zerolog.Event) {
e.Str("name", u.Name).
Str("email", u.Email).
Int64("createdAt", u.CreatedAt.UnixNano())
}

func (uu users) MarshalZerologArray(a *zerolog.Array) {
for _, u := range uu {
a.Object(u)
}
}

func fakeZerologFields(e *zerolog.Event) *zerolog.Event {
return e.
Int("int", _tenInts[0]).
Interface("ints", _tenInts).
Ints("ints", _tenInts).
Str("string", _tenStrings[0]).
Interface("strings", _tenStrings).
Strs("strings", _tenStrings).
Time("time", _tenTimes[0]).
Interface("times", _tenTimes).
Interface("user1", _oneUser).
Interface("user2", _oneUser).
Interface("users", _tenUsers).
Times("times", _tenTimes).
Object("user1", _oneUser).
Object("user2", _oneUser).
Array("users", _tenUsers).
Err(errExample)
}

func fakeZerologContext(c zerolog.Context) zerolog.Context {
return c.
Int("int", _tenInts[0]).
Interface("ints", _tenInts).
Ints("ints", _tenInts).
Str("string", _tenStrings[0]).
Interface("strings", _tenStrings).
Strs("strings", _tenStrings).
Time("time", _tenTimes[0]).
Interface("times", _tenTimes).
Interface("user1", _oneUser).
Interface("user2", _oneUser).
Interface("users", _tenUsers).
Times("times", _tenTimes).
Object("user1", _oneUser).
Object("user2", _oneUser).
Array("users", _tenUsers).
Err(errExample)
}

0 comments on commit 34cb012

Please sign in to comment.