From 010ad86837fbcd65ca02eb44f6f10fe42fb19c30 Mon Sep 17 00:00:00 2001 From: Matt Schallert Date: Wed, 20 Mar 2019 12:29:08 -0400 Subject: [PATCH 1/2] [coordinator] disable stack traces in logs It's often clear where errors are coming from. When stack traces are enabled, if a coordinator is being used as a prom backend and there's an error with the M3DB cluster then every single prom write causes a stack trace and the logs quickly fill up, making debugging difficult. --- src/query/util/logging/log.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/query/util/logging/log.go b/src/query/util/logging/log.go index d48a8cba2b..3599c503c4 100644 --- a/src/query/util/logging/log.go +++ b/src/query/util/logging/log.go @@ -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" @@ -70,7 +70,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() } From 8c9ffe97aa331b5971fbc0f5f33ac91c6608c273 Mon Sep 17 00:00:00 2001 From: Artem Nikolayevsky Date: Wed, 20 Mar 2019 15:05:37 -0400 Subject: [PATCH 2/2] Explicitly add stack traces to panics --- src/query/util/logging/log.go | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/src/query/util/logging/log.go b/src/query/util/logging/log.go index 3599c503c4..67d8a3920c 100644 --- a/src/query/util/logging/log.go +++ b/src/query/util/logging/log.go @@ -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) @@ -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() {