-
Notifications
You must be signed in to change notification settings - Fork 2
/
logger.go
38 lines (31 loc) · 611 Bytes
/
logger.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
package main
import (
"log/syslog"
"os"
"github.com/sirupsen/logrus"
lSyslog "github.com/sirupsen/logrus/hooks/syslog"
)
var (
logger *logrus.Logger
)
func GetLogger(name, level string, logsys bool) *logrus.Logger {
log := logrus.New()
log.Out = os.Stdout
log.SetFormatter(&logrus.TextFormatter{
ForceColors: true,
DisableTimestamp: true,
})
lvl, err := logrus.ParseLevel(level)
if err != nil {
panic(err)
}
log.SetLevel(lvl)
if logsys {
hook, err := lSyslog.NewSyslogHook("", "", syslog.LOG_INFO, name)
if err != nil {
panic(err)
}
log.AddHook(hook)
}
return log
}