-
Notifications
You must be signed in to change notification settings - Fork 61
/
logger.go
44 lines (37 loc) · 812 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
39
40
41
42
43
44
package qrpc
import (
"fmt"
"github.com/zhiqiangxu/util/logger"
"go.uber.org/zap"
)
var (
// Logger if exported for overwrite
l *zap.Logger
)
// Logger returns the logger for qrpc
func Logger() *zap.Logger {
return l
}
// SetLogger for change zap.Logger
// should only be called in init func
func SetLogger(zl *zap.Logger) {
l = zl
}
func init() {
if l == nil {
var err error
config := zap.Config{
DisableCaller: true,
DisableStacktrace: true,
Level: zap.NewAtomicLevelAt(zap.InfoLevel),
Encoding: "json",
EncoderConfig: zap.NewDevelopmentEncoderConfig(),
OutputPaths: []string{"stdout"},
ErrorOutputPaths: []string{"stderr"},
}
l, err = logger.New(config)
if err != nil {
panic(fmt.Sprintf("qrpc.zap.Build:%v", err))
}
}
}