Skip to content

InterfaceMarshalFunc is not called when encoding JSON #651

@moritzploss-k

Description

@moritzploss-k

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?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions