Skip to content

Commit

Permalink
add SetOpts to logger
Browse files Browse the repository at this point in the history
  • Loading branch information
veceraj committed Dec 11, 2024
1 parent 5c6c91f commit d3388cb
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 0 deletions.
3 changes: 3 additions & 0 deletions pbm/log/discard.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {}
Expand Down
1 change: 1 addition & 0 deletions pbm/log/log.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
20 changes: 20 additions & 0 deletions pbm/log/logger.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()})
}

0 comments on commit d3388cb

Please sign in to comment.