rs/zerolog

InterfaceMarshalFunc is not called when encoding JSON

Opened this issue · 2 comments

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 commented

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

alright, thanks for clarifying!