-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathlogging.go
42 lines (35 loc) · 817 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
35
36
37
38
39
40
41
42
package main
import (
"os"
"strings"
log "github.com/Sirupsen/logrus"
"github.com/olebedev/config"
)
func configLogging(cfg *config.Config) {
// Set verbosity
verbosity, _ := cfg.String("log.level")
switch verbosity {
case "debug":
log.SetLevel(log.DebugLevel)
case "warning":
log.SetLevel(log.WarnLevel)
case "error":
log.SetLevel(log.ErrorLevel)
default:
verbosity = "info"
log.SetLevel(log.InfoLevel)
}
log.SetOutput(os.Stdout)
logDest, _ := cfg.String("log.destination")
if len(logDest) == 0 {
logDest = "stdout"
}
if strings.HasPrefix(logDest, "syslog://") {
if err := syslogging(strings.TrimPrefix(logDest, "syslog://")); err != nil {
log.Error(err)
os.Exit(1)
}
return
}
log.Debugf("Log Settings: [level: %s, dest: %s]", strings.ToUpper(verbosity), logDest)
}