generated from openacid/gotmpl
-
Notifications
You must be signed in to change notification settings - Fork 2
/
logging.go
59 lines (47 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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
package traft
import (
"encoding/json"
"go.uber.org/zap"
)
var (
llg = zap.NewNop()
lg *zap.SugaredLogger
)
func initLogging() {
// if os.Getenv("CLUSTER_DEBUG") != "" {
// }
var err error
// llg, err = zap.NewProduction()
llg, err = zap.NewDevelopment()
if err != nil {
panic(err)
}
lg = llg.Sugar()
// initZap()
}
func initZap() {
rawJSON := []byte(`{
"level": "debug",
"encoding": "json",
"outputPaths": ["stdout", "/tmp/logs"],
"errorOutputPaths": ["stderr"],
"initialFields": {"foo": "bar"},
"encoderConfig": {
"messageKey": "message",
"levelKey": "level",
"levelEncoder": "lowercase"
}
}`)
var cfg zap.Config
if err := json.Unmarshal(rawJSON, &cfg); err != nil {
panic(err)
}
var err error
llg, err = cfg.Build()
if err != nil {
panic(err)
}
defer llg.Sync()
llg.Info("logger construction succeeded")
lg = llg.Sugar()
}