Skip to content

Commit

Permalink
fix(log): do not increase error-metric on warning-logs (#884)
Browse files Browse the repository at this point in the history
BEDS-90
  • Loading branch information
guybrush authored Sep 25, 2024
1 parent 9f8ef50 commit 1686af5
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions backend/pkg/commons/log/log.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,17 @@ import (
// Fatal logs a fatal error with callstack info that skips callerSkip many levels with arbitrarily many additional infos.
// callerSkip equal to 0 gives you info directly where Fatal is called.
func Fatal(err error, errorMsg interface{}, callerSkip int, additionalInfos ...Fields) {
logErrorInfo(err, callerSkip, additionalInfos...).Fatal(errorMsg)
logErrorInfo(err, callerSkip, false, additionalInfos...).Fatal(errorMsg)
}

// Error logs an error with callstack info that skips callerSkip many levels with arbitrarily many additional infos.
// callerSkip equal to 0 gives you info directly where Error is called.
func Error(err error, errorMsg interface{}, callerSkip int, additionalInfos ...Fields) {
logErrorInfo(err, callerSkip, additionalInfos...).Error(errorMsg)
logErrorInfo(err, callerSkip, false, additionalInfos...).Error(errorMsg)
}

func WarnWithStackTrace(err error, errorMsg interface{}, callerSkip int, additionalInfos ...Fields) {
logErrorInfo(err, callerSkip, additionalInfos...).Warn(errorMsg)
logErrorInfo(err, callerSkip, true, additionalInfos...).Warn(errorMsg)
}

func Info(args ...interface{}) {
Expand Down Expand Up @@ -67,7 +67,7 @@ func Debugf(format string, args ...interface{}) {
logrus.Debugf(format, args...)
}

func logErrorInfo(err error, callerSkip int, additionalInfos ...Fields) *logrus.Entry {
func logErrorInfo(err error, callerSkip int, isWarning bool, additionalInfos ...Fields) *logrus.Entry {
logFields := logrus.NewEntry(logrus.New())

metricName := "unknown"
Expand All @@ -88,7 +88,9 @@ func logErrorInfo(err error, callerSkip int, additionalInfos ...Fields) *logrus.
if len(metricName) > 30 {
metricName = metricName[len(metricName)-30:]
}
metrics.Errors.WithLabelValues(metricName).Inc()
if !isWarning {
metrics.Errors.WithLabelValues(metricName).Inc()
}

errColl := []string{}
for {
Expand Down

0 comments on commit 1686af5

Please sign in to comment.