1/*
2 *
3 * Copyright 2020 gRPC authors.
4 *
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 *
17 */
18
19package channelz
20
21import (
22 "fmt"
23
24 "google.golang.org/grpc/grpclog"
25)
26
27var logger = grpclog.Component("channelz")
28
29// Info logs and adds a trace event if channelz is on.
30func Info(l grpclog.DepthLoggerV2, e Entity, args ...any) {
31 AddTraceEvent(l, e, 1, &TraceEvent{
32 Desc: fmt.Sprint(args...),
33 Severity: CtInfo,
34 })
35}
36
37// Infof logs and adds a trace event if channelz is on.
38func Infof(l grpclog.DepthLoggerV2, e Entity, format string, args ...any) {
39 AddTraceEvent(l, e, 1, &TraceEvent{
40 Desc: fmt.Sprintf(format, args...),
41 Severity: CtInfo,
42 })
43}
44
45// Warning logs and adds a trace event if channelz is on.
46func Warning(l grpclog.DepthLoggerV2, e Entity, args ...any) {
47 AddTraceEvent(l, e, 1, &TraceEvent{
48 Desc: fmt.Sprint(args...),
49 Severity: CtWarning,
50 })
51}
52
53// Warningf logs and adds a trace event if channelz is on.
54func Warningf(l grpclog.DepthLoggerV2, e Entity, format string, args ...any) {
55 AddTraceEvent(l, e, 1, &TraceEvent{
56 Desc: fmt.Sprintf(format, args...),
57 Severity: CtWarning,
58 })
59}
60
61// Error logs and adds a trace event if channelz is on.
62func Error(l grpclog.DepthLoggerV2, e Entity, args ...any) {
63 AddTraceEvent(l, e, 1, &TraceEvent{
64 Desc: fmt.Sprint(args...),
65 Severity: CtError,
66 })
67}
68
69// Errorf logs and adds a trace event if channelz is on.
70func Errorf(l grpclog.DepthLoggerV2, e Entity, format string, args ...any) {
71 AddTraceEvent(l, e, 1, &TraceEvent{
72 Desc: fmt.Sprintf(format, args...),
73 Severity: CtError,
74 })
75}