-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlogging.go
More file actions
executable file
·64 lines (58 loc) · 1.73 KB
/
Copy pathlogging.go
File metadata and controls
executable file
·64 lines (58 loc) · 1.73 KB
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
60
61
62
63
64
package utils
import (
"strings"
"go.uber.org/zap"
"go.uber.org/zap/zapcore"
)
// --------------------------------------------------------------------------------
// DebugLevel logs are typically voluminous, and are usually disabled in
// production.
// DebugLevel Level = iota - 1
//
// InfoLevel is the default logging priority.
// InfoLevel
//
// WarnLevel logs are more important than Info, but don't need individual
// human review.
// WarnLevel
//
// ErrorLevel logs are high-priority. If an application is running smoothly,
// it shouldn't generate any error-level logs.
// ErrorLevel
//
// DPanicLevel logs are particularly important errors. In development the
// logger panics after writing the message.
// DPanicLevel
//
// PanicLevel logs a message, then panics.
// PanicLevel
//
// FatalLevel logs a message, then calls os.Exit(1).
// FatalLevel
// --------------------------------------------------------------------------------
func NewLogger(logLevel string) *zap.SugaredLogger {
myLevel := strings.ToUpper(strings.TrimSpace(logLevel))
level, err := zapcore.ParseLevel(myLevel)
if err != nil {
level = zapcore.InfoLevel
}
cfg := zap.Config{
Encoding: "console",
Level: zap.NewAtomicLevelAt(level),
OutputPaths: []string{"stderr"},
ErrorOutputPaths: []string{"stderr"},
EncoderConfig: zapcore.EncoderConfig{
MessageKey: "message",
LevelKey: "level",
//EncodeLevel: zapcore.CapitalColorLevelEncoder,
EncodeLevel: zapcore.LowercaseColorLevelEncoder,
TimeKey: "time",
EncodeTime: zapcore.ISO8601TimeEncoder,
// EncodeTime: zapcore.RFC3339TimeEncoder,
// CallerKey: "caller",
// EncodeCaller: zapcore.ShortCallerEncoder,
},
}
logger, _ := cfg.Build()
return logger.Sugar()
}