-
Notifications
You must be signed in to change notification settings - Fork 0
/
kira_log.go
51 lines (43 loc) · 1.24 KB
/
kira_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
package kira
import (
"io"
"os"
"github.com/go-kira/kira/modules/config"
"github.com/go-kira/kira/modules/log"
lumberjack "gopkg.in/natefinch/lumberjack.v2"
)
func setupLogger(config *config.Config, w io.Writer, fields log.Fields) *log.Logger {
logger := log.New(w, setupFormatter(config), fields)
logger.SetLevel(log.LevelStrings[config.GetString("log.level", "info")])
return logger
}
func setupWriter(config *config.Config) io.Writer {
switch config.GetString("log.log") {
case "stderr":
return os.Stderr
case "stdin":
return os.Stdin
case "stdout":
return os.Stdout
case "file":
return &lumberjack.Logger{
Filename: config.GetString("log.file", "./storage/logs/kira.log"),
MaxSize: config.GetInt("log.file_max_size", 100),
MaxBackups: config.GetInt("log.file_max_backups", 3),
MaxAge: config.GetInt("log.file_max_age", 28),
Compress: config.GetBool("log.file_max_compress", false),
}
}
return os.Stderr
}
// setupFormatter to setup the logger formatter.
func setupFormatter(config *config.Config) log.Formatter {
switch config.GetString("log.formatter") {
case "default":
case "cli":
return log.NewDefaultFormatter()
case "json":
return log.NewJSONFormatter()
}
return log.NewDefaultFormatter()
}