-
Notifications
You must be signed in to change notification settings - Fork 3
/
log.go
58 lines (50 loc) · 990 Bytes
/
log.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
package main
import (
log "github.com/sirupsen/logrus"
"os"
"sync"
)
const defaultLogLevel = log.InfoLevel
var (
once sync.Once
instance log.Logger
)
func LogLevel(levelName string) log.Level {
/**
Set the log level of logrus following the value supplied in the configuration
*/
var logLevel log.Level
switch levelName {
case "debug":
logLevel = log.DebugLevel
case "info":
logLevel = log.InfoLevel
case "warn":
logLevel = log.WarnLevel
case "error":
logLevel = log.ErrorLevel
case "fatal":
logLevel = log.FatalLevel
case "panic":
logLevel = log.PanicLevel
default:
logLevel = defaultLogLevel
}
return logLevel
}
func getLogger(config *Config) log.Logger {
/**
Singleton to get the same logger instance everywhere
*/
once.Do(func() {
instance = log.Logger{
Out: os.Stderr,
Level: LogLevel(config.defaultLogLevel),
Formatter: &log.TextFormatter{
DisableColors: true,
FullTimestamp: true,
},
}
})
return instance
}