Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dict arrays #111

Closed
mgurevin opened this issue Oct 25, 2018 · 7 comments · Fixed by #375
Closed

Dict arrays #111

mgurevin opened this issue Oct 25, 2018 · 7 comments · Fixed by #375

Comments

@mgurevin
Copy link

Is there a method for adding zerolog.Dict objects to inside zerolog.Array?

I want to log things like following structure:

{
	"foo": [
		{"foo": "bar", "baz": 42},
		{"foo": "bar", "baz": 42}
	],
	"bar": [
		{"foo": "bar", "baz": 42},
		{"foo": "bar", "baz": 42}
	]
}

I was thinking to make this like that:

zerolog.  
	Dict("foo", zerolog.Arr().
		Dict(zerolog.Dict().Str("foo", "bar").Int("baz", 42)).
		Dict(zerolog.Dict().Str("foo", "bar").Int("baz", 42))).
	Dict("bar", zerolog.Arr().
		Dict(zerolog.Dict().Str("foo", "bar").Int("baz", 42)).
		Dict(zerolog.Dict().Str("foo", "bar").Int("baz", 42)))

But I can't see Dict method in the zerolog.Array struct.

Thanks.

@rs
Copy link
Owner

rs commented Oct 25, 2018

You can use Interface for this.

@rs rs closed this as completed Nov 7, 2018
@mgurevin
Copy link
Author

mgurevin commented Nov 8, 2018

Of course, but it comes a little bit reflection cost. I think array supports like DICT is better than JSON marshaling.

@rs
Copy link
Owner

rs commented Nov 8, 2018

You're right. I just don't have the need for such complex structure, so I can't promise I'll add it. If you want to give it a try, I'm all for it.

@mgurevin
Copy link
Author

I faced the same situation right now and had completely forgotten this message, and Google brought me up here again two years later :)

Is anybody else asked?

@rs
Copy link
Owner

rs commented Feb 18, 2020

Not that I know of :)

@mgurevin
Copy link
Author

oh, maybe I'll send a PR next time I come back :)

fgsch added a commit to fgsch/zerolog that referenced this issue Nov 1, 2021
@fgsch
Copy link
Contributor

fgsch commented Nov 1, 2021

I'm needing this so I will open a PR for consideration.

rs pushed a commit that referenced this issue Nov 2, 2021
pablitoc pushed a commit to nxcr-org/zerolog that referenced this issue Apr 7, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants