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

How to disable stack trace in wrn and err level ? #27

Open
sintanial opened this issue Mar 12, 2016 · 3 comments
Open

How to disable stack trace in wrn and err level ? #27

sintanial opened this issue Mar 12, 2016 · 3 comments

Comments

@sintanial
Copy link

Hello, i need to disable stack trace in WRN and ERROR level, how to do this ?

@fgrosse
Copy link

fgrosse commented Apr 5, 2016

If you generally want to supress stack traces on specific logger calls you can always pass the error message instead of the entire error:

log.Error("Oh noe", "error", err)         // will generate a stacktrace
log.Error("Oh noe", "error", err.Error()) // will not generate a stacktrace

@sintanial
Copy link
Author

unfortunately log.Error always generate stack trace :(, your method worked only with warning.

@pschultz
Copy link

Please consider adding an option to disable automatic stacktraces with the HappyDevFormatter. The traces generated by debug.Stack are quite useless.

Consider this program:

package main

import (
        "errors"

        "github.com/mgutz/logxi/v1"
)

func main() {
        err := f()
        log.Info("fatal", "err", err)
}

func f() error {
        return g()
}

func g() error {
        return errors.New("fail")
}

The automatic trace is something like

$ go run main.go  
21:17:02.595604 ERR ~ fatal err: fail
goroutine 1 [running]:
runtime/debug.Stack(0x10, 0xc420045a68, 0x4bf5c0)
        /usr/local/go/src/runtime/debug/stack.go:24 +0x79
github.com/mgutz/logxi/v1.(*HappyDevFormatter).getLevelContext(0xc42000e900, 0x3, 0xc420014c90, 0x0, 0x0, 0x0, 0x0, 0xc42000ac58, 0x5)
        /tmp/tmp.j9F8IpiHwM/main.go:21 +0x137

This mentions neither f, nor g. There are packages that provide much more relevant traces, such as github.com/pkg/errors. When I log these traces explicitly the automatic traces are confusing.

$ go run main.go  
21:16:31.119270 ERR ~ fatal err: fail
   trace: main.g
        /tmp/tmp.j9F8IpiHwM/main.go:26
main.f
        /tmp/tmp.j9F8IpiHwM/main.go:22
main.main
        /tmp/tmp.j9F8IpiHwM/main.go:11
runtime.main
        /usr/local/go/src/runtime/proc.go:183
runtime.goexit
        /usr/local/go/src/runtime/asm_amd64.s:2086
goroutine 1 [running]:
runtime/debug.Stack(0x10, 0xc4200459f0, 0x4c0d10)
        /usr/local/go/src/runtime/debug/stack.go:24 +0x79
github.com/mgutz/logxi/v1.(*HappyDevFormatter).getLevelContext(0xc42000e900, 0x3, 0xc420014d80, 0x0, 0x0, 0x0, 0x0, 0xc42000ac58, 0x5)
        /tmp/tmp.j9F8IpiHwM/main.go:18 +0x31f

var disableCallstack bool already exists. Can we just export that?

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

3 participants