aboutsummaryrefslogtreecommitdiffstats
path: root/community/gitlab-runner/use-logrus-syslog-hook.patch
blob: 676e65d4875b52fbb9e0255bd513605fa0bbbb6e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
Replace gitlab-runner/log/system_logger with standard logrus/hooks/syslog.
There are two reasons:

1. gitlab-runner/log/system_logger delegates the syslog initialization
   (syslog.Dial) to kardianos/service, which doesn't set the syslog
   facility. This results in messages logged with the "kern" facility.
2. gitlab-runner/log/system_logger maps Error, Panic, and Fatal levels
   to the syslog's "err" level, but Panic and Fatal could be mapped to
   the "crit" level.

I didn't contribute this patch to the upstream because I don't wanna
contribute to any Go projects. However, if you find this patch useful,
feel free to send it to the upstream under your name.

--- a/commands/multi.go
+++ b/commands/multi.go
@@ -30,6 +30,9 @@
 	"gitlab.com/gitlab-org/gitlab-runner/log"
 	"gitlab.com/gitlab-org/gitlab-runner/network"
 	"gitlab.com/gitlab-org/gitlab-runner/session"
+
+	"log/syslog"
+	lSyslog "github.com/sirupsen/logrus/hooks/syslog"
 )
 
 var (
@@ -997,7 +1000,13 @@
 	}
 
 	if mr.Syslog {
-		log.SetSystemLogger(logrus.StandardLogger(), svc)
+		hook, err := lSyslog.NewSyslogHook("", "", syslog.LOG_DAEMON | syslog.LOG_INFO, mr.ServiceName)
+		if err == nil {
+			logrus.AddHook(hook)
+		} else {
+			logrus.WithError(err).
+				Error("Error while setting up the system logger")
+		}
 	}
 
 	logrus.AddHook(&mr.sentryLogHook)