-
Notifications
You must be signed in to change notification settings - Fork 1
/
syslogger.go
63 lines (57 loc) · 1.69 KB
/
syslogger.go
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
package logger
import (
"io/ioutil"
"log/syslog"
log "github.com/sirupsen/logrus"
logrus_syslog "github.com/sirupsen/logrus/hooks/syslog"
)
func initSyslogger(config LogConfig) *log.Logger {
var logSeverity = map[string]syslog.Priority{
"LOG_EMERG": syslog.LOG_EMERG,
"LOG_ALERT": syslog.LOG_ALERT,
"LOG_CRIT": syslog.LOG_CRIT,
"LOG_ERR": syslog.LOG_ERR,
"LOG_WARNING": syslog.LOG_WARNING,
"LOG_NOTICE": syslog.LOG_NOTICE,
"LOG_INFO": syslog.LOG_INFO,
"LOG_DEBUG": syslog.LOG_DEBUG,
}
var logFacility = map[string]syslog.Priority{
"LOG_KERN": syslog.LOG_KERN,
"LOG_USER": syslog.LOG_USER,
"LOG_MAIL": syslog.LOG_MAIL,
"LOG_DAEMON": syslog.LOG_DAEMON,
"LOG_AUTH": syslog.LOG_AUTH,
"LOG_SYSLOG": syslog.LOG_SYSLOG,
"LOG_LPR": syslog.LOG_LPR,
"LOG_NEWS": syslog.LOG_NEWS,
"LOG_UUCP": syslog.LOG_UUCP,
"LOG_CRON": syslog.LOG_CRON,
"LOG_AUTHPRIV": syslog.LOG_AUTHPRIV,
"LOG_FTP": syslog.LOG_FTP,
"LOG_LOCAL0": syslog.LOG_LOCAL0,
"LOG_LOCAL1": syslog.LOG_LOCAL1,
"LOG_LOCAL2": syslog.LOG_LOCAL2,
"LOG_LOCAL3": syslog.LOG_LOCAL3,
"LOG_LOCAL4": syslog.LOG_LOCAL4,
"LOG_LOCAL5": syslog.LOG_LOCAL5,
"LOG_LOCAL6": syslog.LOG_LOCAL6,
"LOG_LOCAL7": syslog.LOG_LOCAL7,
}
logger := log.New()
hook, err := logrus_syslog.NewSyslogHook(
config.NetworkType,
config.Host+":"+config.Port,
logSeverity[config.Severity]|logFacility[config.Facility],
config.Title)
if err != nil {
log.Errorln(err)
hook, err = logrus_syslog.NewSyslogHook(
"", "", logSeverity[config.Severity]|logFacility[config.Facility],
config.Title)
} else {
logger.Hooks.Add(hook)
}
logger.Out = ioutil.Discard
return logger
}