Browse Source

Improve logging

Brendan Abolivier 7 years ago
parent
commit
a32c62d5ed
Signed by: Brendan Abolivier <contact@brendanabolivier.com> GPG key ID: 8EF1500759F70623
1 changed files with 12 additions and 5 deletions
  1. 12
    5
      src/metrics-alerting/alert/alert.go

+ 12
- 5
src/metrics-alerting/alert/alert.go View File

21
 	labels map[string]string,
21
 	labels map[string]string,
22
 	data script_data.Data,
22
 	data script_data.Data,
23
 ) error {
23
 ) error {
24
-	alertLog := fmt.Sprintf("Test for script \"%s\" failed", script.Key)
25
-	if len(data.Key) > 0 {
26
-		alertLog = alertLog + fmt.Sprintf(" (data: %s=%s)", data.Key, data.Value)
27
-	}
28
-	logrus.Info(alertLog)
24
+	logFailure(script, data)
29
 
25
 
30
 	switch script.Action {
26
 	switch script.Action {
31
 	case "http":
27
 	case "http":
36
 		return fmt.Errorf("invalid action type: %s", script.Action)
32
 		return fmt.Errorf("invalid action type: %s", script.Action)
37
 	}
33
 	}
38
 }
34
 }
35
+
36
+func logFailure(script config.Script, data script_data.Data) {
37
+	var entry *logrus.Entry
38
+	if len(data.Key) > 0 {
39
+		entry = logrus.WithField(data.Key, data.Value)
40
+	} else {
41
+		entry = logrus.NewEntry(logrus.New())
42
+	}
43
+
44
+	entry.Infof("Test for script \"%s\" failed", script.Key)
45
+}