Skip to content

Conversation

@hhk7734
Copy link
Contributor

@hhk7734 hhk7734 commented Jul 3, 2023

When I want to log a sub dictionary, it's hard to find that I can just log zap.Object("k", ObjectMarshalerFunc(func(inner ObjectEncoder) error { ... })), and it seems unintuitive.

So I added zap.Dict.

Example

zap.Dict("1",
	zap.String("1-1", "b"),
	zap.Bool("1-2", true),
	zap.Dict("1-3",
		zap.String("1-3-1", "d"),
	),
),
{"1": {"1-1": "b", "1-2": true, "1-3": {"1-3-1": "d"}}}
{
  "1": {
    "1-1": "b",
    "1-2": true,
    "1-3": {
      "1-3-1": "d"
    }
  }
}

@CLAassistant
Copy link

CLAassistant commented Jul 3, 2023

CLA assistant check
All committers have signed the CLA.

@codecov
Copy link

codecov bot commented Aug 14, 2023

Codecov Report

Merging #1297 (c19628d) into master (5da8736) will increase coverage by 0.15%.
The diff coverage is 100.00%.

@@            Coverage Diff             @@
##           master    #1297      +/-   ##
==========================================
+ Coverage   97.61%   97.77%   +0.15%     
==========================================
  Files          52       52              
  Lines        3355     3366      +11     
==========================================
+ Hits         3275     3291      +16     
+ Misses         69       65       -4     
+ Partials       11       10       -1     
Files Changed Coverage Δ
field.go 100.00% <100.00%> (ø)

... and 1 file with indirect coverage changes

📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more

Copy link
Collaborator

@abhinav abhinav left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, @hhk7734. This is a great idea!
I've made some changes to the implementation. Namely, instead of adding a new field type, I've implemented this functionality outside in terms of a new private ObjectMarshaler implementation. That way, the zapcore package doesn't see any changes (except new tests).

The change LGTM, but I'd like to get another maintainer to also look over it.
CC @mway @sywhang @prashantv

@mway
Copy link
Contributor

mway commented Aug 14, 2023

LGTM - thanks @hhk7734 and @abhinav!

@mway mway merged commit fcfd368 into uber-go:master Aug 14, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

4 participants