Skip to content

Commit

Permalink
Calm down OCR's logging unless VerboseLogging or TraceLogging is enabled
Browse files Browse the repository at this point in the history
  • Loading branch information
samsondav committed Nov 14, 2024
1 parent 2cd5c75 commit 76a6aad
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 1 deletion.
2 changes: 1 addition & 1 deletion core/services/llo/delegate.go
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ func (d *delegate) Start(ctx context.Context) error {
case 1:
lggr = logger.With(lggr, "instanceType", "Green")
}
ocrLogger := logger.NewOCRWrapper(lggr, d.cfg.TraceLogging, func(msg string) {
ocrLogger := logger.NewOCRWrapper(NewSuppressedLogger(lggr, d.cfg.ReportingPluginConfig.VerboseLogging), d.cfg.TraceLogging, func(msg string) {
// TODO: do we actually need to DB-persist errors?
// MERC-3524
})
Expand Down
51 changes: 51 additions & 0 deletions core/services/llo/suppressed_logger.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
package llo

import "github.com/smartcontractkit/chainlink-common/pkg/logger"

// Suppressed logger swallows debug/info unless the verbose flag is turned on
// Useful for OCR to calm down its verbosity

var _ logger.Logger = &SuppressedLogger{}

func NewSuppressedLogger(lggr logger.Logger, verbose bool) logger.Logger {
return &SuppressedLogger{
Logger: lggr,
Verbose: verbose,
}
}

type SuppressedLogger struct {
logger.Logger
Verbose bool
}

func (s *SuppressedLogger) Debug(args ...interface{}) {
if s.Verbose {
s.Logger.Debug(args...)
}
}
func (s *SuppressedLogger) Info(args ...interface{}) {
if s.Verbose {
s.Logger.Info(args...)
}
}
func (s *SuppressedLogger) Debugf(format string, values ...interface{}) {
if s.Verbose {
s.Logger.Debugf(format, values...)
}
}
func (s *SuppressedLogger) Infof(format string, values ...interface{}) {
if s.Verbose {
s.Logger.Infof(format, values...)
}
}
func (s *SuppressedLogger) Debugw(msg string, keysAndValues ...interface{}) {
if s.Verbose {
s.Logger.Debugw(msg, keysAndValues...)
}
}
func (s *SuppressedLogger) Infow(msg string, keysAndValues ...interface{}) {
if s.Verbose {
s.Logger.Infow(msg, keysAndValues...)
}
}

0 comments on commit 76a6aad

Please sign in to comment.