Skip to content

Commit

Permalink
doc: Clarify documentation, add example test
Browse files Browse the repository at this point in the history
  • Loading branch information
abhinav committed Aug 14, 2023
1 parent d0bde18 commit c19628d
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
13 changes: 13 additions & 0 deletions example_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -358,3 +358,16 @@ func ExampleWrapCore_wrap() {
// {"level":"info","msg":"doubled"}
// {"level":"info","msg":"doubled"}
}

func ExampleDict() {
logger := zap.NewExample()
defer logger.Sync()

logger.Info("login event",
zap.Dict("event",
zap.Int("id", 123),
zap.String("name", "jane"),
zap.String("status", "pending")))
// Output:
// {"level":"info","msg":"login event","event":{"id":123,"name":"jane","status":"pending"}}
}
3 changes: 2 additions & 1 deletion field.go
Original file line number Diff line number Diff line change
Expand Up @@ -410,7 +410,8 @@ func Inline(val zapcore.ObjectMarshaler) Field {
}
}

// Dict constructs a field with the given key and Fields.
// Dict constructs a field containing the provided key-value pairs.
// It acts similar to [Object], but with the fields specified as arguments.
func Dict(key string, val ...Field) Field {
return dictField(key, val)
}
Expand Down

0 comments on commit c19628d

Please sign in to comment.