-
Notifications
You must be signed in to change notification settings - Fork 0
/
grpclog.go
79 lines (67 loc) · 2.07 KB
/
grpclog.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
package log
import (
"fmt"
"go.uber.org/zap"
"go.uber.org/zap/zapcore"
)
// grpclog
func (l *Logger) V(level int) bool {
level -= 2
return l.Logger.Core().Enabled(zapcore.Level(level))
}
// // 等同于xxxln,为了实现某些接口 如grpclog
func (l *Logger) Infoln(args ...any) {
if ce := l.Check(zap.InfoLevel, fmt.Sprint(args...)); ce != nil {
ce.Write()
}
}
func (l *Logger) Warning(args ...any) {
if ce := l.Check(zap.WarnLevel, fmt.Sprint(args...)); ce != nil {
ce.Write()
}
}
func (l *Logger) Warningln(args ...any) {
if ce := l.Check(zap.WarnLevel, fmt.Sprint(args...)); ce != nil {
ce.Write()
}
}
// grpclog
func (l *Logger) Warningf(template string, args ...any) {
if ce := l.Check(zap.WarnLevel, fmt.Sprintf(template, args...)); ce != nil {
ce.Write()
}
}
func (l *Logger) Errorln(args ...any) {
if ce := l.Check(zap.ErrorLevel, fmt.Sprint(args...)); ce != nil {
ce.Write()
}
}
func (l *Logger) Fatalln(args ...any) {
if ce := l.Check(zap.FatalLevel, fmt.Sprint(args...)); ce != nil {
ce.Write()
}
}
// InfoDepth logs to INFO log at the specified depth. Arguments are handled in the manner of fmt.Println.
func (l *Logger) InfoDepth(depth int, args ...any) {
if ce := l.Check(zap.InfoLevel, trimLineBreak(fmt.Sprintln(args...))); ce != nil {
ce.Write()
}
}
// WarningDepth logs to WARNING log at the specified depth. Arguments are handled in the manner of fmt.Println.
func (l *Logger) WarningDepth(depth int, args ...any) {
if ce := l.Check(zap.WarnLevel, trimLineBreak(fmt.Sprintln(args...))); ce != nil {
ce.Write()
}
}
// ErrorDepth logs to ERROR log at the specified depth. Arguments are handled in the manner of fmt.Println.
func (l *Logger) ErrorDepth(depth int, args ...any) {
if ce := l.Check(zap.ErrorLevel, trimLineBreak(fmt.Sprintln(args...))); ce != nil {
ce.Write()
}
}
// FatalDepth logs to FATAL log at the specified depth. Arguments are handled in the manner of fmt.Println.
func (l *Logger) FatalDepth(depth int, args ...any) {
if ce := l.Check(zap.FatalLevel, trimLineBreak(fmt.Sprintln(args...))); ce != nil {
ce.Write()
}
}