From f9953c173e6e5f9499d5fe62fb4b7dad8f293ad1 Mon Sep 17 00:00:00 2001 From: Mark Mandel Date: Fri, 19 Jan 2018 11:25:50 -0800 Subject: [PATCH] Output the stack error as an actual array This just makes debugging of stacks easier. --- pkg/util/runtime/runtime.go | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/pkg/util/runtime/runtime.go b/pkg/util/runtime/runtime.go index 9fa3fdc235..24c906d57c 100644 --- a/pkg/util/runtime/runtime.go +++ b/pkg/util/runtime/runtime.go @@ -17,14 +17,30 @@ package runtime import ( + "fmt" + + "github.com/pkg/errors" "github.com/sirupsen/logrus" "k8s.io/apimachinery/pkg/util/runtime" ) +// stackTracer is the pkg/errors stacktrace interface +type stackTracer interface { + StackTrace() errors.StackTrace +} + // replace the standard glog error logger, with a logrus one func init() { runtime.ErrorHandlers[0] = func(err error) { - logrus.Errorf("stack: %+v", err) + if err, ok := err.(stackTracer); ok { + var stack []string + for _, f := range err.StackTrace() { + stack = append(stack, fmt.Sprintf("%+v", f)) + } + logrus.WithField("stack", stack).Error(err) + } else { + logrus.Error(err) + } } }