Scott Baker | 105df15 | 2020-04-13 15:55:14 -0700 | [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/internal/grpclog" |
| 25 | ) |
| 26 | |
| 27 | // Info logs through grpclog.Info and adds a trace event if channelz is on. |
| 28 | func Info(id int64, args ...interface{}) { |
| 29 | if IsOn() { |
| 30 | AddTraceEvent(id, 1, &TraceEventDesc{ |
| 31 | Desc: fmt.Sprint(args...), |
| 32 | Severity: CtINFO, |
| 33 | }) |
| 34 | } else { |
| 35 | grpclog.InfoDepth(1, args...) |
| 36 | } |
| 37 | } |
| 38 | |
| 39 | // Infof logs through grpclog.Infof and adds a trace event if channelz is on. |
| 40 | func Infof(id int64, format string, args ...interface{}) { |
| 41 | msg := fmt.Sprintf(format, args...) |
| 42 | if IsOn() { |
| 43 | AddTraceEvent(id, 1, &TraceEventDesc{ |
| 44 | Desc: msg, |
| 45 | Severity: CtINFO, |
| 46 | }) |
| 47 | } else { |
| 48 | grpclog.InfoDepth(1, msg) |
| 49 | } |
| 50 | } |
| 51 | |
| 52 | // Warning logs through grpclog.Warning and adds a trace event if channelz is on. |
| 53 | func Warning(id int64, args ...interface{}) { |
| 54 | if IsOn() { |
| 55 | AddTraceEvent(id, 1, &TraceEventDesc{ |
| 56 | Desc: fmt.Sprint(args...), |
| 57 | Severity: CtWarning, |
| 58 | }) |
| 59 | } else { |
| 60 | grpclog.WarningDepth(1, args...) |
| 61 | } |
| 62 | } |
| 63 | |
| 64 | // Warningf logs through grpclog.Warningf and adds a trace event if channelz is on. |
| 65 | func Warningf(id int64, format string, args ...interface{}) { |
| 66 | msg := fmt.Sprintf(format, args...) |
| 67 | if IsOn() { |
| 68 | AddTraceEvent(id, 1, &TraceEventDesc{ |
| 69 | Desc: msg, |
| 70 | Severity: CtWarning, |
| 71 | }) |
| 72 | } else { |
| 73 | grpclog.WarningDepth(1, msg) |
| 74 | } |
| 75 | } |
| 76 | |
| 77 | // Error logs through grpclog.Error and adds a trace event if channelz is on. |
| 78 | func Error(id int64, args ...interface{}) { |
| 79 | if IsOn() { |
| 80 | AddTraceEvent(id, 1, &TraceEventDesc{ |
| 81 | Desc: fmt.Sprint(args...), |
| 82 | Severity: CtError, |
| 83 | }) |
| 84 | } else { |
| 85 | grpclog.ErrorDepth(1, args...) |
| 86 | } |
| 87 | } |
| 88 | |
| 89 | // Errorf logs through grpclog.Errorf and adds a trace event if channelz is on. |
| 90 | func Errorf(id int64, format string, args ...interface{}) { |
| 91 | msg := fmt.Sprintf(format, args...) |
| 92 | if IsOn() { |
| 93 | AddTraceEvent(id, 1, &TraceEventDesc{ |
| 94 | Desc: msg, |
| 95 | Severity: CtError, |
| 96 | }) |
| 97 | } else { |
| 98 | grpclog.ErrorDepth(1, msg) |
| 99 | } |
| 100 | } |