/
logger.go
84 lines (66 loc) · 1.83 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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
package grpcerr
import (
"fmt"
"go.uber.org/zap"
"go.uber.org/zap/zapcore"
"google.golang.org/grpc/grpclog"
)
const (
component = "component"
componentName = "grpc"
)
// logger implements grpclog.LoggerV2 helps investigate at least warning errors in stdout during clint outage
type logger struct {
*zap.Logger
}
func New(in *zap.Logger) grpclog.LoggerV2 {
return &logger{Logger: in.With(zap.String(component, componentName))}
}
func (l logger) Info(args ...interface{}) {
l.Logger.Debug(fmt.Sprint(args...))
}
func (l logger) Infoln(args ...interface{}) {
l.Logger.Debug(fmt.Sprint(args...))
}
func (l logger) Infof(format string, args ...interface{}) {
l.Logger.Debug(fmt.Sprintf(format, args...))
}
func (l logger) Warning(args ...interface{}) {
l.Logger.WithOptions(
zap.WithCaller(false),
zap.AddStacktrace(zapcore.FatalLevel),
).Error(fmt.Sprint(args...))
}
func (l logger) Warningln(args ...interface{}) {
l.Logger.WithOptions(
zap.WithCaller(false),
zap.AddStacktrace(zapcore.FatalLevel),
).Error(fmt.Sprint(args...))
}
func (l logger) Warningf(format string, args ...interface{}) {
l.Logger.WithOptions(
zap.WithCaller(false),
zap.AddStacktrace(zapcore.FatalLevel),
).Error(fmt.Sprintf(format, args...))
}
func (l logger) Error(args ...interface{}) {
l.Logger.Error(fmt.Sprint(args...))
}
func (l logger) Errorln(args ...interface{}) {
l.Logger.Error(fmt.Sprint(args...))
}
func (l logger) Errorf(format string, args ...interface{}) {
l.Logger.Error(fmt.Sprintf(format, args...))
}
func (l logger) Fatal(args ...interface{}) {
l.Logger.Fatal(fmt.Sprint(args...))
}
func (l logger) Fatalln(args ...interface{}) {
l.Logger.Fatal(fmt.Sprint(args...))
}
func (l logger) Fatalf(format string, args ...interface{}) {
l.Logger.Fatal(fmt.Sprintf(format, args...))
}
func (l logger) V(_ int) bool {
return true
}