blob: 8e13a3d2ce7b6e13a0fd3019461929007ef88973 [file] [log] [blame]
khenaidoo5fc5cea2021-08-11 17:39:16 -04001/*
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
Akash Kankanala761955c2024-02-21 19:32:20 +053029func withParens(id *Identifier) string {
30 return "[" + id.String() + "] "
31}
32
khenaidoo5fc5cea2021-08-11 17:39:16 -040033// Info logs and adds a trace event if channelz is on.
Akash Kankanala761955c2024-02-21 19:32:20 +053034func Info(l grpclog.DepthLoggerV2, id *Identifier, args ...interface{}) {
35 AddTraceEvent(l, id, 1, &TraceEventDesc{
36 Desc: fmt.Sprint(args...),
37 Severity: CtInfo,
38 })
khenaidoo5fc5cea2021-08-11 17:39:16 -040039}
40
41// Infof logs and adds a trace event if channelz is on.
Akash Kankanala761955c2024-02-21 19:32:20 +053042func Infof(l grpclog.DepthLoggerV2, id *Identifier, format string, args ...interface{}) {
43 AddTraceEvent(l, id, 1, &TraceEventDesc{
44 Desc: fmt.Sprintf(format, args...),
45 Severity: CtInfo,
46 })
khenaidoo5fc5cea2021-08-11 17:39:16 -040047}
48
49// Warning logs and adds a trace event if channelz is on.
Akash Kankanala761955c2024-02-21 19:32:20 +053050func Warning(l grpclog.DepthLoggerV2, id *Identifier, args ...interface{}) {
51 AddTraceEvent(l, id, 1, &TraceEventDesc{
52 Desc: fmt.Sprint(args...),
53 Severity: CtWarning,
54 })
khenaidoo5fc5cea2021-08-11 17:39:16 -040055}
56
57// Warningf logs and adds a trace event if channelz is on.
Akash Kankanala761955c2024-02-21 19:32:20 +053058func Warningf(l grpclog.DepthLoggerV2, id *Identifier, format string, args ...interface{}) {
59 AddTraceEvent(l, id, 1, &TraceEventDesc{
60 Desc: fmt.Sprintf(format, args...),
61 Severity: CtWarning,
62 })
khenaidoo5fc5cea2021-08-11 17:39:16 -040063}
64
65// Error logs and adds a trace event if channelz is on.
Akash Kankanala761955c2024-02-21 19:32:20 +053066func Error(l grpclog.DepthLoggerV2, id *Identifier, args ...interface{}) {
67 AddTraceEvent(l, id, 1, &TraceEventDesc{
68 Desc: fmt.Sprint(args...),
69 Severity: CtError,
70 })
khenaidoo5fc5cea2021-08-11 17:39:16 -040071}
72
73// Errorf logs and adds a trace event if channelz is on.
Akash Kankanala761955c2024-02-21 19:32:20 +053074func Errorf(l grpclog.DepthLoggerV2, id *Identifier, format string, args ...interface{}) {
75 AddTraceEvent(l, id, 1, &TraceEventDesc{
76 Desc: fmt.Sprintf(format, args...),
77 Severity: CtError,
78 })
khenaidoo5fc5cea2021-08-11 17:39:16 -040079}