Skip to content

Commit

Permalink
MAde min level configurable
Browse files Browse the repository at this point in the history
  • Loading branch information
mattiasavelin committed Oct 11, 2023
1 parent bdf17e5 commit 689f303
Showing 1 changed file with 26 additions and 1 deletion.
27 changes: 26 additions & 1 deletion pkg/logging/logger.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand All @@ -24,6 +48,7 @@ type LoggerWithContext struct {
type LoggerConfig struct {
OnGCP bool
ServiceName string
MinLevel Level
}

func NewLogger(config *LoggerConfig) *Logger {
Expand All @@ -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),
),
}
Expand Down

0 comments on commit 689f303

Please sign in to comment.