-
Notifications
You must be signed in to change notification settings - Fork 0
/
zap.go
51 lines (43 loc) · 1.12 KB
/
zap.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
47
48
49
50
51
package engine
import (
"io"
"github.com/gin-gonic/gin"
"github.com/openshift/installer/pkg/lineprinter"
"go.uber.org/zap"
"go.uber.org/zap/zapcore"
)
var (
DefaultWriter io.Writer
DefaultLevel zapcore.Level = zapcore.DebugLevel
DefaultMsg string = "GIN"
DefaultKey string = "L"
DefaultErrorWriter io.Writer
DefaultErrorLevel zapcore.Level = zapcore.ErrorLevel
DefaultErrorMsg string = "GIN"
DefaultErrorKey string = "L"
)
func init() {
DefaultWriter = printer(func(line interface{}) {
if ce := zap.L().Check(DefaultLevel, DefaultMsg); ce != nil {
ce.Write(zap.Any(DefaultKey, line))
}
})
DefaultErrorWriter = printer(func(line interface{}) {
if ce := zap.L().Check(DefaultErrorLevel, DefaultErrorMsg); ce != nil {
ce.Write(zap.Any(DefaultErrorKey, line))
}
})
gin.DefaultWriter = DefaultWriter
gin.DefaultErrorWriter = DefaultErrorWriter
}
func printer(p func(interface{})) io.Writer {
return &lineprinter.LinePrinter{
Print: (&lineprinter.Trimmer{
WrappedPrint: func(args ...interface{}) {
for _, a := range args {
p(a)
}
},
}).Print,
}
}