...
1
18
19 package grpclog
20
21 import (
22 "fmt"
23
24 "google.golang.org/grpc/internal/grpclog"
25 )
26
27
28 type componentData struct {
29 name string
30 }
31
32 var cache = map[string]*componentData{}
33
34 func (c *componentData) InfoDepth(depth int, args ...any) {
35 args = append([]any{"[" + string(c.name) + "]"}, args...)
36 grpclog.InfoDepth(depth+1, args...)
37 }
38
39 func (c *componentData) WarningDepth(depth int, args ...any) {
40 args = append([]any{"[" + string(c.name) + "]"}, args...)
41 grpclog.WarningDepth(depth+1, args...)
42 }
43
44 func (c *componentData) ErrorDepth(depth int, args ...any) {
45 args = append([]any{"[" + string(c.name) + "]"}, args...)
46 grpclog.ErrorDepth(depth+1, args...)
47 }
48
49 func (c *componentData) FatalDepth(depth int, args ...any) {
50 args = append([]any{"[" + string(c.name) + "]"}, args...)
51 grpclog.FatalDepth(depth+1, args...)
52 }
53
54 func (c *componentData) Info(args ...any) {
55 c.InfoDepth(1, args...)
56 }
57
58 func (c *componentData) Warning(args ...any) {
59 c.WarningDepth(1, args...)
60 }
61
62 func (c *componentData) Error(args ...any) {
63 c.ErrorDepth(1, args...)
64 }
65
66 func (c *componentData) Fatal(args ...any) {
67 c.FatalDepth(1, args...)
68 }
69
70 func (c *componentData) Infof(format string, args ...any) {
71 c.InfoDepth(1, fmt.Sprintf(format, args...))
72 }
73
74 func (c *componentData) Warningf(format string, args ...any) {
75 c.WarningDepth(1, fmt.Sprintf(format, args...))
76 }
77
78 func (c *componentData) Errorf(format string, args ...any) {
79 c.ErrorDepth(1, fmt.Sprintf(format, args...))
80 }
81
82 func (c *componentData) Fatalf(format string, args ...any) {
83 c.FatalDepth(1, fmt.Sprintf(format, args...))
84 }
85
86 func (c *componentData) Infoln(args ...any) {
87 c.InfoDepth(1, args...)
88 }
89
90 func (c *componentData) Warningln(args ...any) {
91 c.WarningDepth(1, args...)
92 }
93
94 func (c *componentData) Errorln(args ...any) {
95 c.ErrorDepth(1, args...)
96 }
97
98 func (c *componentData) Fatalln(args ...any) {
99 c.FatalDepth(1, args...)
100 }
101
102 func (c *componentData) V(l int) bool {
103 return V(l)
104 }
105
106
107
108
109
110 func Component(componentName string) DepthLoggerV2 {
111 if cData, ok := cache[componentName]; ok {
112 return cData
113 }
114 c := &componentData{componentName}
115 cache[componentName] = c
116 return c
117 }
118
View as plain text