zerolog icon indicating copy to clipboard operation
zerolog copied to clipboard

ErrorStackFieldName is not taken into account in PartsExclude

Open WinXaito opened this issue 4 years ago • 1 comments

I want to be able to export the stack to a JSON file but not to the console (ConsoleWriter).

ConsoleWriter initialization:

consoleWriter := zerolog.NewConsoleWriter()
consoleWriter.TimeFormat = "02/01/2006 15:04:05.000"
consoleWriter.PartsExclude = []string{zerolog.CallerFieldName, zerolog.ErrorStackFieldName}

Call:

err := errors.New("a test error")
log.Error().Stack().Err(err).Send()

With this:

consoleWriter.PartsExclude = []string{}

Output:

11/11/2021 10:15:18.000 ERR ***/main.go:36 >  error="a test error" stack=[{"func":"main","line":"35","source":"main.go"},{"func":"main","line":"225","source":"proc.go"},{"func":"goexit","line":"841","source":"asm_arm.s"}]

And with excluded parts:

consoleWriter.PartsExclude = []string{zerolog.CallerFieldName, zerolog.ErrorStackFieldName}

Output: (The caller is not here, but the stack is)

11/11/2021 10:15:18.000 ERR  error="a test error" stack=[{"func":"main","line":"35","source":"main.go"},{"func":"main","line":"225","source":"proc.go"},{"func":"goexit","line":"841","source":"asm_arm.s"}]

Expected output:

11/11/2021 10:15:18.000 ERR  error="a test error"

WinXaito avatar Nov 11 '21 10:11 WinXaito

Stack trace is a field, while caller is a part. You want #411.

mitar avatar Feb 23 '22 23:02 mitar