forked from KasperskyLab/klogga
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgrpc_adapter.go
117 lines (99 loc) · 2.46 KB
/
grpc_adapter.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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
package grpc
import (
"context"
"fmt"
"github.com/KasperskyLab/klogga"
)
type LoggerV2 struct {
trs klogga.Tracer
conf *Conf
}
type Conf struct {
VerbosityLevel klogga.LogLevel
}
func NewLoggerV2(trs klogga.TracerProvider, conf *Conf) *LoggerV2 {
return &LoggerV2{trs: trs.Named("grpc"), conf: conf}
}
func (g LoggerV2) trace(level klogga.LogLevel, mes string) {
span := klogga.StartLeaf(context.Background())
defer g.trs.Finish(span)
span.Level(level).Val("message", mes)
}
func (g LoggerV2) Info(args ...interface{}) {
if g.conf.VerbosityLevel <= klogga.Info {
return
}
g.trace(klogga.Info, fmt.Sprint(args...))
}
func (g LoggerV2) Infoln(args ...interface{}) {
if g.conf.VerbosityLevel <= klogga.Info {
return
}
g.trace(klogga.Info, fmt.Sprint(args...))
}
func (g LoggerV2) Infof(format string, args ...interface{}) {
if g.conf.VerbosityLevel <= klogga.Info {
return
}
g.trace(klogga.Info, fmt.Sprintf(format, args...))
}
func (g LoggerV2) Warning(args ...interface{}) {
if g.conf.VerbosityLevel <= klogga.Warn {
return
}
g.trace(klogga.Warn, fmt.Sprint(args...))
}
func (g LoggerV2) Warningln(args ...interface{}) {
if g.conf.VerbosityLevel <= klogga.Warn {
return
}
g.trace(klogga.Warn, fmt.Sprint(args...))
}
func (g LoggerV2) Warningf(format string, args ...interface{}) {
if g.conf.VerbosityLevel <= klogga.Warn {
return
}
g.trace(klogga.Warn, fmt.Sprintf(format, args...))
}
func (g LoggerV2) Error(args ...interface{}) {
if g.conf.VerbosityLevel <= klogga.Error {
return
}
g.trace(klogga.Error, fmt.Sprint(args...))
}
func (g LoggerV2) Errorln(args ...interface{}) {
if g.conf.VerbosityLevel <= klogga.Error {
return
}
g.trace(klogga.Error, fmt.Sprint(args...))
}
func (g LoggerV2) Errorf(format string, args ...interface{}) {
if g.conf.VerbosityLevel <= klogga.Error {
return
}
g.trace(klogga.Error, fmt.Sprintf(format, args...))
}
func (g LoggerV2) Fatal(args ...interface{}) {
if g.conf.VerbosityLevel <= klogga.Fatal {
return
}
g.trace(klogga.Fatal, fmt.Sprint(args...))
}
func (g LoggerV2) Fatalln(args ...interface{}) {
if g.conf.VerbosityLevel <= klogga.Fatal {
return
}
g.trace(klogga.Fatal, fmt.Sprint(args...))
}
func (g LoggerV2) Fatalf(format string, args ...interface{}) {
if g.conf.VerbosityLevel <= klogga.Fatal {
return
}
g.trace(klogga.Fatal, fmt.Sprintf(format, args...))
}
func (g LoggerV2) V(l int) bool {
if g.conf.VerbosityLevel == 0 {
return true
}
return l >= int(g.conf.VerbosityLevel)
}