diff --git a/core/logger/ocr_wrapper.go b/core/logger/ocr_wrapper.go deleted file mode 100644 index 865a5cac736..00000000000 --- a/core/logger/ocr_wrapper.go +++ /dev/null @@ -1,62 +0,0 @@ -package logger - -import ( - ocrtypes "github.com/smartcontractkit/libocr/commontypes" -) - -var _ ocrtypes.Logger = &ocrWrapper{} - -type ocrWrapper struct { - internal Logger - trace bool - saveError func(string) -} - -// Deprecated: use github.com/smartcontractkit/chainlink-relay/pkg/logger.NewOCRWrapper instead. -func NewOCRWrapper(l Logger, trace bool, saveError func(string)) ocrtypes.Logger { - return &ocrWrapper{ - internal: l.Helper(2), - trace: trace, - saveError: saveError, - } -} - -// TODO(sam): Zap does not support trace level logging yet, so this hack is -// necessary to silence excessive logging -func (ol *ocrWrapper) Trace(msg string, fields ocrtypes.LogFields) { - if ol.trace { - ol.internal.Debugw(msg, toKeysAndValues(fields)...) - } -} - -func (ol *ocrWrapper) Debug(msg string, fields ocrtypes.LogFields) { - ol.internal.Debugw(msg, toKeysAndValues(fields)...) -} - -func (ol *ocrWrapper) Info(msg string, fields ocrtypes.LogFields) { - ol.internal.Infow(msg, toKeysAndValues(fields)...) -} - -func (ol *ocrWrapper) Warn(msg string, fields ocrtypes.LogFields) { - ol.internal.Warnw(msg, toKeysAndValues(fields)...) -} - -// Note that the structured fields may contain dynamic data (timestamps etc.) -// So when saving the error, we only save the top level string, details -// are included in the log. -func (ol *ocrWrapper) Error(msg string, fields ocrtypes.LogFields) { - ol.saveError(msg) - ol.internal.Errorw(msg, toKeysAndValues(fields)...) -} - -func (ol *ocrWrapper) Critical(msg string, fields ocrtypes.LogFields) { - ol.internal.Criticalw(msg, toKeysAndValues(fields)...) -} - -func toKeysAndValues(fields ocrtypes.LogFields) []interface{} { - out := []interface{}{} - for key, val := range fields { - out = append(out, key, val) - } - return out -} diff --git a/core/logger/ocr_wrapper_test.go b/core/logger/ocr_wrapper_test.go deleted file mode 100644 index 249998343f2..00000000000 --- a/core/logger/ocr_wrapper_test.go +++ /dev/null @@ -1,51 +0,0 @@ -package logger - -import ( - "testing" - - "github.com/smartcontractkit/libocr/commontypes" - "github.com/stretchr/testify/assert" -) - -func TestOCRWrapper(t *testing.T) { - t.Parallel() - - testFields := commontypes.LogFields{ - "field": 123, - } - - args := []interface{}{"msg"} - args = append(args, toKeysAndValues(testFields)...) - - ml := NewMockLogger(t) - ml.On("Helper", 2).Return(ml).Once() - ml.On("Debugw", args...).Twice() // due to Trace - ml.On("Infow", args...).Once() - ml.On("Warnw", args...).Once() - ml.On("Criticalw", args...).Once() - ml.On("Errorw", args...).Once() - - var savedError string - saveError := func(err string) { - savedError = err - } - - w := NewOCRWrapper(ml, true, saveError) - w.Trace("msg", testFields) - w.Debug("msg", testFields) - w.Info("msg", testFields) - w.Warn("msg", testFields) - w.Critical("msg", testFields) - w.Error("msg", testFields) - assert.Equal(t, "msg", savedError) -} - -func TestOCRWrapper_NoTrace(t *testing.T) { - t.Parallel() - - ml := NewMockLogger(t) - ml.On("Helper", 2).Return(ml).Once() - - w := NewOCRWrapper(ml, false, nil) - w.Trace("msg", commontypes.LogFields{}) -} diff --git a/core/services/feeds/config.go b/core/services/feeds/config.go index 5850f4fc885..605e70c24c9 100644 --- a/core/services/feeds/config.go +++ b/core/services/feeds/config.go @@ -25,4 +25,5 @@ type OCR2Config interface { ContractPollInterval() time.Duration ContractTransmitterTransmitTimeout() time.Duration DatabaseTimeout() time.Duration + TraceLogging() bool } diff --git a/core/services/ocr2/delegate.go b/core/services/ocr2/delegate.go index addd9cb721a..ecd8c1c84c6 100644 --- a/core/services/ocr2/delegate.go +++ b/core/services/ocr2/delegate.go @@ -630,12 +630,12 @@ func (d *Delegate) ServicesForSpec(jb job.Job) ([]job.ServiceCtx, error) { "jobName", jb.Name.ValueOrZero(), "jobID", jb.ID, ) - vrfLogger := logger.NewOCRWrapper(l.With( - "vrfContractID", spec.ContractID), true, func(msg string) { + vrfLogger := relaylogger.NewOCRWrapper(l.With( + "vrfContractID", spec.ContractID), d.cfg.OCR2().TraceLogging(), func(msg string) { lggr.ErrorIf(d.jobORM.RecordError(jb.ID, msg), "unable to record error") }) - dkgLogger := logger.NewOCRWrapper(l.With( - "dkgContractID", cfg.DKGContractAddress), true, func(msg string) { + dkgLogger := relaylogger.NewOCRWrapper(l.With( + "dkgContractID", cfg.DKGContractAddress), d.cfg.OCR2().TraceLogging(), func(msg string) { lggr.ErrorIf(d.jobORM.RecordError(jb.ID, msg), "unable to record error") }) dkgReportingPluginFactoryDecorator := func(wrapped ocr2types.ReportingPluginFactory) ocr2types.ReportingPluginFactory { diff --git a/core/services/ocr2/plugins/functions/reporting_test.go b/core/services/ocr2/plugins/functions/reporting_test.go index 225d5f78d39..bb0a5239375 100644 --- a/core/services/ocr2/plugins/functions/reporting_test.go +++ b/core/services/ocr2/plugins/functions/reporting_test.go @@ -11,6 +11,7 @@ import ( "github.com/smartcontractkit/libocr/commontypes" "github.com/smartcontractkit/libocr/offchainreporting2plus/types" + relaylogger "github.com/smartcontractkit/chainlink-relay/pkg/logger" "github.com/smartcontractkit/chainlink/v2/core/internal/testutils" "github.com/smartcontractkit/chainlink/v2/core/logger" functions_srv "github.com/smartcontractkit/chainlink/v2/core/services/functions" @@ -22,7 +23,7 @@ import ( func preparePlugin(t *testing.T, batchSize uint32) (types.ReportingPlugin, *functions_mocks.ORM, *encoding.ReportCodec) { lggr := logger.TestLogger(t) - ocrLogger := logger.NewOCRWrapper(lggr, true, func(msg string) {}) + ocrLogger := relaylogger.NewOCRWrapper(lggr, true, func(msg string) {}) orm := functions_mocks.NewORM(t) factory := functions.FunctionsReportingPluginFactory{ Logger: ocrLogger, diff --git a/core/services/ocr2/validate/config.go b/core/services/ocr2/validate/config.go index 912ff30cc52..abcb24aaa12 100644 --- a/core/services/ocr2/validate/config.go +++ b/core/services/ocr2/validate/config.go @@ -15,6 +15,7 @@ type OCR2Config interface { ContractPollInterval() time.Duration ContractTransmitterTransmitTimeout() time.Duration DatabaseTimeout() time.Duration + TraceLogging() bool } type InsecureConfig interface { diff --git a/core/services/ocrbootstrap/delegate.go b/core/services/ocrbootstrap/delegate.go index e5507979ad3..c4ce1218293 100644 --- a/core/services/ocrbootstrap/delegate.go +++ b/core/services/ocrbootstrap/delegate.go @@ -8,6 +8,7 @@ import ( ocr "github.com/smartcontractkit/libocr/offchainreporting2plus" "github.com/smartcontractkit/sqlx" + relaylogger "github.com/smartcontractkit/chainlink-relay/pkg/logger" "github.com/smartcontractkit/chainlink-relay/pkg/loop" "github.com/smartcontractkit/chainlink-relay/pkg/types" @@ -115,7 +116,7 @@ func (d *Delegate) ServicesForSpec(jobSpec job.Job) (services []job.ServiceCtx, ContractConfigTracker: configProvider.ContractConfigTracker(), Database: NewDB(d.db.DB, spec.ID, lggr), LocalConfig: lc, - Logger: logger.NewOCRWrapper(lggr.Named("OCRBootstrap"), true, func(msg string) { + Logger: relaylogger.NewOCRWrapper(lggr.Named("OCRBootstrap"), d.ocr2Cfg.TraceLogging(), func(msg string) { logger.Sugared(lggr).ErrorIf(d.jobORM.RecordError(jobSpec.ID, msg), "unable to record error") }), OffchainConfigDigester: configProvider.OffchainConfigDigester(),