forked from hi-glenn/xdp_acl
-
Notifications
You must be signed in to change notification settings - Fork 1
/
log.go
46 lines (38 loc) · 1.01 KB
/
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
package main
import (
"github.com/natefinch/lumberjack"
"go.uber.org/zap"
"go.uber.org/zap/zapcore"
)
var zlog *zap.SugaredLogger
func init() {
writeSyncer := getLogWriter()
encoder := getEncoder()
core := zapcore.NewCore(
encoder,
// zapcore.NewMultiWriteSyncer(zapcore.AddSync(os.Stdout), writeSyncer),
zapcore.NewMultiWriteSyncer(writeSyncer),
zapcore.InfoLevel,
// zapcore.DebugLevel,
)
logger := zap.New(core, zap.AddCaller())
zlog = logger.Sugar()
}
func getEncoder() zapcore.Encoder {
encoderConfig := zap.NewProductionEncoderConfig()
encoderConfig.EncodeTime = zapcore.ISO8601TimeEncoder
encoderConfig.EncodeLevel = zapcore.CapitalLevelEncoder
// encoderConfig.CallerKey = "linenum"
return zapcore.NewConsoleEncoder(encoderConfig)
}
func getLogWriter() zapcore.WriteSyncer {
lumberJackLogger := &lumberjack.Logger{
Filename: "./log/acl.log",
MaxSize: 10, // MByte
MaxBackups: 5,
MaxAge: 30,
Compress: false,
LocalTime: true,
}
return zapcore.AddSync(lumberJackLogger)
}