diff --git a/pbm/log/discard.go b/pbm/log/discard.go index 985dee4ad..c80e07607 100644 --- a/pbm/log/discard.go +++ b/pbm/log/discard.go @@ -54,6 +54,9 @@ func (discardLoggerImpl) Output(ctx context.Context, e *Entry) error { return nil } +func (discardLoggerImpl) SetOpts(cfg *Opts) { +} + type discardEventImpl struct{} func (discardEventImpl) Debug(msg string, args ...any) {} diff --git a/pbm/log/log.go b/pbm/log/log.go index faa0dd0ba..8b22804b0 100644 --- a/pbm/log/log.go +++ b/pbm/log/log.go @@ -35,6 +35,7 @@ type Logger interface { Error(event, obj, opid string, epoch primitive.Timestamp, msg string, args ...any) Fatal(event, obj, opid string, epoch primitive.Timestamp, msg string, args ...any) Output(ctx context.Context, e *Entry) error + SetOpts(cfg *Opts) } type LogEvent interface { diff --git a/pbm/log/logger.go b/pbm/log/logger.go index 659d108c2..3cad43b25 100644 --- a/pbm/log/logger.go +++ b/pbm/log/logger.go @@ -305,3 +305,23 @@ func (l *loggerImpl) Output(ctx context.Context, e *Entry) error { return rerr } + +func (l *loggerImpl) SetOpts(cfg *Opts) { + if cfg == nil { + return + } + + l.mu.Lock() + defer l.mu.Unlock() + if cfg.LogPath != "" && l.logger.logPath != cfg.LogPath { + l.createLogger(cfg.LogPath) + } + if cfg.LogLevel != "" && l.logLevel.String() != cfg.LogLevel { + l.logLevel = strToSeverity(cfg.LogLevel) + } + if l.logJSON != cfg.LogJSON { + l.logJSON = cfg.LogJSON + } + + fmt.Printf("Updated log options: %+v\n", &Opts{l.logger.logPath, l.logJSON, l.logLevel.String()}) +}