From 8a6ab8d263c9dd7524dbac4cb712d83fc8eb2a2d Mon Sep 17 00:00:00 2001 From: dmytrozakharenko Date: Wed, 31 Jul 2024 16:46:43 -0400 Subject: [PATCH] - log "did not find pid match for data frame" only 2 times --- internal/hooks/loghooks.go | 7 +++++++ internal/loggers/dbc_passive_logger.go | 3 ++- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/internal/hooks/loghooks.go b/internal/hooks/loghooks.go index 2ef5603..2b08d45 100644 --- a/internal/hooks/loghooks.go +++ b/internal/hooks/loghooks.go @@ -146,6 +146,13 @@ func LogInfo(logger zerolog.Logger, message string, opts ...LogOption) { logger.Info().Ctx(c).Msg(message) } +// LogWarn logs a warn message with the provided options. +func LogWarn(logger zerolog.Logger, message string, opts ...LogOption) { + c := applyOptions(opts) + + logger.Warn().Ctx(c).Msg(message) +} + func applyOptions(opts []LogOption) context.Context { options := &logOptions{} for _, opt := range opts { diff --git a/internal/loggers/dbc_passive_logger.go b/internal/loggers/dbc_passive_logger.go index d77b357..076473b 100644 --- a/internal/loggers/dbc_passive_logger.go +++ b/internal/loggers/dbc_passive_logger.go @@ -131,7 +131,8 @@ func (dpl *dbcPassiveLogger) StartScanning(ch chan<- models.SignalData) error { } ch <- s } else { - dpl.logger.Warn().Msgf("did not find pid match for data frame: %s", printBytesAsHex(frame.Data)) + msg := fmt.Sprintf("did not find pid match for data frame: %s", printBytesAsHex(frame.Data)) + hooks.LogWarn(dpl.logger, msg, hooks.WithStopLogAfter(2)) } // this frame won't be processed by the DBC filter continue