-
Notifications
You must be signed in to change notification settings - Fork 0
/
logger.go
43 lines (31 loc) · 1.01 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
package loadtester
import (
"time"
"go.uber.org/zap"
"go.uber.org/zap/zapcore"
)
type SugaredLogger interface {
// Fatalw will call os.Exit(1), so use with care only when it makes sense
Fatalw(msg string, keysAndValues ...interface{})
Debugw(msg string, keysAndValues ...interface{})
Warnw(msg string, keysAndValues ...interface{})
Errorw(msg string, keysAndValues ...interface{})
Infow(msg string, keysAndValues ...interface{})
// Panicw will panic, so use with care
Panicw(msg string, keysAndValues ...interface{})
}
func NewLogger(logLevel zapcore.Level) (*zap.SugaredLogger, error) {
cfg := zap.NewProductionConfig()
cfg.Sampling = nil
cfg.Level = zap.NewAtomicLevelAt(logLevel)
cfg.EncoderConfig.EncodeTime = func(t time.Time, enc zapcore.PrimitiveArrayEncoder) {
zapcore.RFC3339NanoTimeEncoder(t.UTC(), enc)
}
cfg.EncoderConfig.EncodeDuration = zapcore.StringDurationEncoder
cfg.DisableStacktrace = true
logger, err := cfg.Build()
if err != nil {
return nil, err
}
return logger.Sugar(), nil
}