-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdefault.go
More file actions
52 lines (45 loc) · 1.24 KB
/
default.go
File metadata and controls
52 lines (45 loc) · 1.24 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
package log
import (
"os"
"go.uber.org/zap"
"go.uber.org/zap/zapcore"
)
const (
DefaultConsoleStdoutHandlerName = "default-console-stdout-handler"
DefaultConsoleStderrHandlerName = "default-console-stderr-handler"
DefaultFileHandlerName = "default-file-handler"
)
func UseDefaultConsoleHandler() {
RegisterHandler(DefaultConsoleStdoutHandlerName, NewHandler(HandlerConfig{
Type: HandlerTypeText,
Writer: os.Stdout,
WriterSynced: false,
Encoders: HandlerEncoders{
Time: zapcore.TimeEncoderOfLayout("2006-01-02 15:04:05.999"),
},
Enabler: zap.LevelEnablerFunc(func(lvl zapcore.Level) bool {
return lvl < zapcore.ErrorLevel
}),
}))
RegisterHandler(DefaultConsoleStderrHandlerName, NewHandler(HandlerConfig{
Type: HandlerTypeText,
Writer: os.Stderr,
WriterSynced: false,
Encoders: HandlerEncoders{
Time: zapcore.TimeEncoderOfLayout("2006-01-02 15:04:05.999"),
},
Enabler: zapcore.ErrorLevel,
}))
}
func UseDefaultFileHandler(path string) {
file, _, err := zap.Open(path)
if err != nil {
panic(err)
}
RegisterHandler(DefaultFileHandlerName, NewHandler(HandlerConfig{
Type: HandlerTypeText,
Writer: file,
WriterSynced: true,
Enabler: zap.DebugLevel,
}))
}