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

Output the stack error as an actual array #61

Merged
merged 1 commit into from
Jan 19, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 17 additions & 1 deletion pkg/util/runtime/runtime.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}
}

Expand Down