Skip to content

Commit

Permalink
fix logical error (#948)
Browse files Browse the repository at this point in the history
  • Loading branch information
Tofel committed May 10, 2024
1 parent da80c0d commit 539fd52
Showing 1 changed file with 16 additions and 13 deletions.
29 changes: 16 additions & 13 deletions testreporters/reporter_model.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,24 +116,24 @@ func FindAllLogFilesToScan(directoryPath string, partialFilename string) (logFil
return logFilesToScan, err
}

type LogAllowed = bool
type WarnAboutAllowedMsgs = bool

const (
LogAllowed_Yes LogAllowed = true
LogAllowed_No LogAllowed = false
WarnAboutAllowedMsgs_Yes WarnAboutAllowedMsgs = true
WarnAboutAllowedMsgs_No WarnAboutAllowedMsgs = false
)

// AllowedLogMessage is a log message that might be thrown by a Chainlink node during a test, but is not a concern
type AllowedLogMessage struct {
message string
reason string
level zapcore.Level
logWhenFound LogAllowed
logWhenFound WarnAboutAllowedMsgs
}

// NewAllowedLogMessage creates a new AllowedLogMessage. If logWhenFound is true, the log message will be printed to the
// console when found in the log file with Warn level (this can get noisy).
func NewAllowedLogMessage(message string, reason string, level zapcore.Level, logWhenFound LogAllowed) AllowedLogMessage {
func NewAllowedLogMessage(message string, reason string, level zapcore.Level, logWhenFound WarnAboutAllowedMsgs) AllowedLogMessage {
return AllowedLogMessage{
message: message,
reason: reason,
Expand Down Expand Up @@ -169,6 +169,7 @@ func VerifyLogFile(file *os.File, failingLogLevel zapcore.Level, failureThreshol

var logsFound uint

SCANNER_LOOP:
for scanner.Scan() {
jsonLogLine := scanner.Text()
if !strings.HasPrefix(jsonLogLine, "{") { // don't bother with non-json lines
Expand Down Expand Up @@ -212,14 +213,16 @@ func VerifyLogFile(file *os.File, failingLogLevel zapcore.Level, failureThreshol
}

for _, allowedLog := range allAllowedMessages {
if strings.Contains(logMessage.(string), allowedLog.message) && allowedLog.logWhenFound {
log.Warn().
Str("Reason", allowedLog.reason).
Str("Level", allowedLog.level.CapitalString()).
Str("Msg", logMessage.(string)).
Msg("Found allowed log message, ignoring")

continue
if strings.Contains(logMessage.(string), allowedLog.message) {
if allowedLog.logWhenFound {
log.Warn().
Str("Reason", allowedLog.reason).
Str("Level", allowedLog.level.CapitalString()).
Str("Msg", logMessage.(string)).
Msg("Found allowed log message, ignoring")
}

continue SCANNER_LOOP
}
}

Expand Down

0 comments on commit 539fd52

Please sign in to comment.