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

[coordinator] only log stack traces on panic #1480

Merged
merged 2 commits into from
Mar 20, 2019
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
22 changes: 12 additions & 10 deletions src/query/util/logging/log.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ import (

xhttp "github.com/m3db/m3/src/x/net/http"

"github.com/opentracing/opentracing-go"
opentracing "github.com/opentracing/opentracing-go"
"github.com/pborman/uuid"
"go.uber.org/zap"
"go.uber.org/zap/zapcore"
Expand All @@ -45,18 +45,20 @@ const (
undefinedID = "undefined"
)

var logger *zap.Logger
var (
logger *zap.Logger

// InitWithCores is used to set up a new logger.
func InitWithCores(cores []zapcore.Core) {
consoleEncoder := zapcore.NewConsoleEncoder(zap.NewDevelopmentEncoderConfig())

highPriority := zap.LevelEnablerFunc(func(lvl zapcore.Level) bool {
highPriority = zap.LevelEnablerFunc(func(lvl zapcore.Level) bool {
return lvl >= zapcore.ErrorLevel
})
lowPriority := zap.LevelEnablerFunc(func(lvl zapcore.Level) bool {
lowPriority = zap.LevelEnablerFunc(func(lvl zapcore.Level) bool {
return lvl < zapcore.ErrorLevel
})
)

// InitWithCores is used to set up a new logger.
func InitWithCores(cores []zapcore.Core) {
consoleEncoder := zapcore.NewConsoleEncoder(zap.NewDevelopmentEncoderConfig())

consoleErrors := zapcore.Lock(os.Stderr)
consoleDebugging := zapcore.Lock(os.Stdout)
Expand All @@ -70,7 +72,7 @@ func InitWithCores(cores []zapcore.Core) {

core := zapcore.NewTee(cores...)

logger = zap.New(core).WithOptions(zap.AddStacktrace(highPriority))
logger = zap.New(core)
defer logger.Sync()
}

Expand Down Expand Up @@ -162,7 +164,7 @@ func withPanicErrorResponderFunc(

defer func() {
if err := recover(); err != nil {
logger := WithContext(r.Context())
logger := WithContext(r.Context()).WithOptions(zap.AddStacktrace(highPriority))
logger.Error("panic captured", zap.Any("stack", err))

if !writeCheckWriter.Written() {
Expand Down