зеркало из https://github.com/github/vitess-gh.git
make the logging of stacks in errors an opt-in behavior
Signed-off-by: Michael Demmer <mdemmer@slack-corp.com>
This commit is contained in:
Родитель
111d42ee77
Коммит
07f7fab535
|
@ -70,6 +70,7 @@
|
|||
package vterrors
|
||||
|
||||
import (
|
||||
"flag"
|
||||
"fmt"
|
||||
"io"
|
||||
|
||||
|
@ -77,6 +78,12 @@ import (
|
|||
vtrpcpb "vitess.io/vitess/go/vt/proto/vtrpc"
|
||||
)
|
||||
|
||||
var logErrStacks bool
|
||||
|
||||
func init() {
|
||||
flag.BoolVar(&logErrStacks, "logerrstacks", false, "log stack traces in errors")
|
||||
}
|
||||
|
||||
// New returns an error with the supplied message.
|
||||
// New also records the stack trace at the point it was called.
|
||||
func New(code vtrpcpb.Code, message string) error {
|
||||
|
@ -122,7 +129,9 @@ func (f *fundamental) Format(s fmt.State, verb rune) {
|
|||
case 'v':
|
||||
panicIfError(io.WriteString(s, "Code: "+f.code.String()+"\n"))
|
||||
panicIfError(io.WriteString(s, f.msg+"\n"))
|
||||
f.stack.Format(s, verb)
|
||||
if logErrStacks {
|
||||
f.stack.Format(s, verb)
|
||||
}
|
||||
return
|
||||
case 's':
|
||||
panicIfError(io.WriteString(s, f.msg))
|
||||
|
@ -198,7 +207,9 @@ func (w *wrapping) Format(s fmt.State, verb rune) {
|
|||
if rune('v') == verb {
|
||||
panicIfError(fmt.Fprintf(s, "%v\n", w.Cause()))
|
||||
panicIfError(io.WriteString(s, w.msg))
|
||||
w.stack.Format(s, verb)
|
||||
if logErrStacks {
|
||||
w.stack.Format(s, verb)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
|
|
Загрузка…
Ссылка в новой задаче