-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathlogging.go
34 lines (31 loc) · 906 Bytes
/
logging.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
package main
import (
"github.com/Sirupsen/logrus"
"github.com/spf13/viper"
)
func setupLogging() {
switch viper.GetString("log-level") {
case "debug":
logrus.SetLevel(logrus.DebugLevel)
case "info":
logrus.SetLevel(logrus.InfoLevel)
case "warn":
logrus.SetLevel(logrus.WarnLevel)
case "error":
logrus.SetLevel(logrus.ErrorLevel)
case "fatal":
logrus.SetLevel(logrus.FatalLevel)
default:
logrus.WithField("log-level", viper.GetString("log-level")).Warning("invalid log level. defaulting to info.")
logrus.SetLevel(logrus.InfoLevel)
}
switch viper.GetString("log-format") {
case "text":
logrus.SetFormatter(new(logrus.TextFormatter))
case "json":
logrus.SetFormatter(new(logrus.JSONFormatter))
default:
logrus.WithField("log-format", viper.GetString("log-format")).Warning("invalid log format. defaulting to text.")
logrus.SetFormatter(new(logrus.TextFormatter))
}
}