From 689f303625b21ed616777d85cd9c3a9ffd3c8bee Mon Sep 17 00:00:00 2001 From: mattiasavelin Date: Wed, 11 Oct 2023 06:49:08 +0200 Subject: [PATCH] MAde min level configurable --- pkg/logging/logger.go | 27 ++++++++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) diff --git a/pkg/logging/logger.go b/pkg/logging/logger.go index 9fca892..3f36021 100644 --- a/pkg/logging/logger.go +++ b/pkg/logging/logger.go @@ -13,6 +13,30 @@ import ( "google.golang.org/protobuf/proto" ) +// A Level is a logging priority. Higher levels are more important. +type Level int8 + +const ( + // DebugLevel logs are typically voluminous, and are usually disabled in + // production. + DebugLevel Level = iota - 1 + // InfoLevel is the default logging priority. + InfoLevel + // WarnLevel logs are more important than Info, but don't need individual + // human review. + WarnLevel + // ErrorLevel logs are high-priority. If an application is running smoothly, + // it shouldn't generate any error-level logs. + ErrorLevel + // DPanicLevel logs are particularly important errors. In development the + // logger panics after writing the message. + DPanicLevel + // PanicLevel logs a message, then panics. + PanicLevel + // FatalLevel logs a message, then calls os.Exit(1). + FatalLevel +) + type Logger struct { *otelzap.Logger } @@ -24,6 +48,7 @@ type LoggerWithContext struct { type LoggerConfig struct { OnGCP bool ServiceName string + MinLevel Level } func NewLogger(config *LoggerConfig) *Logger { @@ -50,7 +75,7 @@ func NewLogger(config *LoggerConfig) *Logger { // instrumentation otelzap.New( log, - otelzap.WithMinLevel(zap.InfoLevel), + otelzap.WithMinLevel(zapcore.Level(config.MinLevel)), otelzap.WithTraceIDField(true), ), }