From 34cb0124671713fd08967101f4e564c074b51397 Mon Sep 17 00:00:00 2001 From: Steven Masley Date: Wed, 16 Mar 2022 17:46:04 -0500 Subject: [PATCH] Replace 'Interface' usage with correct zerolog api (#1069) Handle structures as documented in zerolog, similar to how zap does in it's test case. --- benchmarks/zerolog_test.go | 36 ++++++++++++++++++++++++------------ 1 file changed, 24 insertions(+), 12 deletions(-) diff --git a/benchmarks/zerolog_test.go b/benchmarks/zerolog_test.go index b14cd9df3..5edb502a8 100644 --- a/benchmarks/zerolog_test.go +++ b/benchmarks/zerolog_test.go @@ -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) }