khenaidoo | 5fc5cea | 2021-08-11 17:39:16 -0400 | [diff] [blame] | 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 | |
| 19 | package channelz |
| 20 | |
| 21 | import ( |
| 22 | "fmt" |
| 23 | |
| 24 | "google.golang.org/grpc/grpclog" |
| 25 | ) |
| 26 | |
| 27 | var logger = grpclog.Component("channelz") |
| 28 | |
Akash Kankanala | 761955c | 2024-02-21 19:32:20 +0530 | [diff] [blame^] | 29 | func withParens(id *Identifier) string { |
| 30 | return "[" + id.String() + "] " |
| 31 | } |
| 32 | |
khenaidoo | 5fc5cea | 2021-08-11 17:39:16 -0400 | [diff] [blame] | 33 | // Info logs and adds a trace event if channelz is on. |
Akash Kankanala | 761955c | 2024-02-21 19:32:20 +0530 | [diff] [blame^] | 34 | func Info(l grpclog.DepthLoggerV2, id *Identifier, args ...interface{}) { |
| 35 | AddTraceEvent(l, id, 1, &TraceEventDesc{ |
| 36 | Desc: fmt.Sprint(args...), |
| 37 | Severity: CtInfo, |
| 38 | }) |
khenaidoo | 5fc5cea | 2021-08-11 17:39:16 -0400 | [diff] [blame] | 39 | } |
| 40 | |
| 41 | // Infof logs and adds a trace event if channelz is on. |
Akash Kankanala | 761955c | 2024-02-21 19:32:20 +0530 | [diff] [blame^] | 42 | func 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 | }) |
khenaidoo | 5fc5cea | 2021-08-11 17:39:16 -0400 | [diff] [blame] | 47 | } |
| 48 | |
| 49 | // Warning logs and adds a trace event if channelz is on. |
Akash Kankanala | 761955c | 2024-02-21 19:32:20 +0530 | [diff] [blame^] | 50 | func Warning(l grpclog.DepthLoggerV2, id *Identifier, args ...interface{}) { |
| 51 | AddTraceEvent(l, id, 1, &TraceEventDesc{ |
| 52 | Desc: fmt.Sprint(args...), |
| 53 | Severity: CtWarning, |
| 54 | }) |
khenaidoo | 5fc5cea | 2021-08-11 17:39:16 -0400 | [diff] [blame] | 55 | } |
| 56 | |
| 57 | // Warningf logs and adds a trace event if channelz is on. |
Akash Kankanala | 761955c | 2024-02-21 19:32:20 +0530 | [diff] [blame^] | 58 | func 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 | }) |
khenaidoo | 5fc5cea | 2021-08-11 17:39:16 -0400 | [diff] [blame] | 63 | } |
| 64 | |
| 65 | // Error logs and adds a trace event if channelz is on. |
Akash Kankanala | 761955c | 2024-02-21 19:32:20 +0530 | [diff] [blame^] | 66 | func Error(l grpclog.DepthLoggerV2, id *Identifier, args ...interface{}) { |
| 67 | AddTraceEvent(l, id, 1, &TraceEventDesc{ |
| 68 | Desc: fmt.Sprint(args...), |
| 69 | Severity: CtError, |
| 70 | }) |
khenaidoo | 5fc5cea | 2021-08-11 17:39:16 -0400 | [diff] [blame] | 71 | } |
| 72 | |
| 73 | // Errorf logs and adds a trace event if channelz is on. |
Akash Kankanala | 761955c | 2024-02-21 19:32:20 +0530 | [diff] [blame^] | 74 | func 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 | }) |
khenaidoo | 5fc5cea | 2021-08-11 17:39:16 -0400 | [diff] [blame] | 79 | } |