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

ErrorStackFieldName is not taken into account in PartsExclude #378

Open
WinXaito opened this issue Nov 11, 2021 · 1 comment
Open

ErrorStackFieldName is not taken into account in PartsExclude #378

WinXaito opened this issue Nov 11, 2021 · 1 comment

Comments

@WinXaito
Copy link

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"
@mitar
Copy link
Contributor

mitar commented Feb 23, 2022

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

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