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