-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathlogger.go
38 lines (35 loc) · 921 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 mermaid
import (
"github.com/keepeye/logrus-filename"
log "github.com/sirupsen/logrus"
"github.com/spf13/viper"
)
// NewLogger return default logger.
func NewLogger() *log.Logger {
logger := log.New()
logger.AddHook(filename.NewHook())
logger.SetFormatter(&log.TextFormatter{
TimestampFormat: "2006-01-02T15:04:05.000",
FullTimestamp: true,
})
return logger
}
// SetLoggerLevel setup logger's log level using viper "log_level" field .
func SetLoggerLevel(logger *log.Logger, cfg *viper.Viper) {
level := cfg.GetString("log_level")
switch level {
case "debug":
logger.SetLevel(log.DebugLevel)
case "info":
logger.SetLevel(log.InfoLevel)
case "warn":
logger.SetLevel(log.WarnLevel)
case "error":
logger.SetLevel(log.ErrorLevel)
case "fatal":
logger.SetLevel(log.FatalLevel)
default:
logger.SetLevel(log.InfoLevel)
}
logger.Infof("Log level: %s", logger.GetLevel().String())
}