-
-
Notifications
You must be signed in to change notification settings - Fork 163
/
Copy pathlogger.go
40 lines (31 loc) · 759 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
package log
import (
// register logfmt encoder
_ "github.com/jsternberg/zap-logfmt"
"go.uber.org/zap"
"go.uber.org/zap/zapcore"
)
type Logger struct {
ZapLogger *zap.Logger
config zap.Config
}
func InitLogger() *Logger {
zapConfig := zap.NewProductionConfig()
zapLogger, _ := zapConfig.Build()
logger := Logger{
ZapLogger: zapLogger,
config: zapConfig,
}
return &logger
}
// Update the logger with a new format and level. Replaces the underlying
// zap.Logger with a new one. Not safe for concurrent use.
func (l *Logger) Update(format string, level zapcore.Level) {
if format == "" {
format = "json"
}
l.config.Level.SetLevel(level)
l.config.Encoding = format
zapLogger, _ := l.config.Build()
l.ZapLogger = zapLogger
}