-
Notifications
You must be signed in to change notification settings - Fork 3
/
logger.go
57 lines (44 loc) · 1.09 KB
/
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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
package main
import (
"os"
"strings"
"time"
"github.com/rs/zerolog"
)
/******************************************************************
* Logger stuff
******************************************************************/
const ComponentField = "component"
const IdField = "identifier"
var PARTS_ORDER = []string{
zerolog.TimestampFieldName,
zerolog.LevelFieldName,
zerolog.CallerFieldName,
zerolog.MessageFieldName,
}
func EnsureLogLevelIsValidElseDefault(logLevel string, defaultValue string) string {
level, e := zerolog.ParseLevel(logLevel)
if nil != e {
return defaultValue
}
return level.String()
}
func GetLoggerLevel(logLevel string) zerolog.Level {
lvl := strings.ToLower(logLevel)
level, e := zerolog.ParseLevel(lvl)
if nil != e {
level = zerolog.Disabled
}
return level
}
func GetLogger(logLevel string) zerolog.Logger {
level := GetLoggerLevel(logLevel)
logger := zerolog.New(zerolog.ConsoleWriter{
Out: os.Stdout,
TimeFormat: time.RFC3339,
PartsOrder: PARTS_ORDER,
})
return logger.Level(level).
With().Timestamp().Logger().
With().Caller().Logger()
}