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

InterfaceMarshalFunc is not called when encoding JSON #651

Open
moritzploss-k opened this issue Feb 23, 2024 · 2 comments
Open

InterfaceMarshalFunc is not called when encoding JSON #651

moritzploss-k opened this issue Feb 23, 2024 · 2 comments

Comments

@moritzploss-k
Copy link

moritzploss-k commented Feb 23, 2024

Description

Hi, and thanks for making zerolog. Maybe I'm missing something, but I fail to make zerolog work with a custom JSON encoder. This is my code:

zerolog.InterfaceMarshalFunc = func(v any) ([]byte, error) {
	fmt.Print("hello")
	return json.MarshalIndent(v, "", strings.Repeat(" ", 4))
}
log.Info().Msg("world")

I would expect zerolog to call my custom InterfaceMarshalFunc to marshal the JSON output (and print hello in the process), but all I get is this:

{"level":"info","message":"world"}

Am I missing something, or is this a bug?

@rs
Copy link
Owner

rs commented Feb 23, 2024

This marshaler is only called when the Interface method is used for a given field. Zerolog does not provide a general pluggable marshaler.

@moritzploss-k
Copy link
Author

alright, thanks for clarifying!

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

No branches or pull requests

2 participants