Skip to content

Duplicate Log Message (ARCH5162)

Key go.logging.duplicate-log-message · Severity info · Category logging

Repeating identical log message strings within the same file or module makes a log line ambiguous about which code path produced it. Each message should distinguish its source.

func update(log *slog.Logger, ok bool) {
if !ok {
log.Warn("operation failed")
}
if err := commit(); err != nil {
log.Warn("operation failed")
}
}
func update(log *slog.Logger, ok bool) {
if !ok {
log.Warn("validation failed")
}
if err := commit(); err != nil {
log.Warn("commit failed", "err", err)
}
}

Give each log call a unique message that disambiguates its context.