google.golang.org/grpc@v1.62.1/internal/channelz/logging.go (about)

     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  
    29  func withParens(id *Identifier) string {
    30  	return "[" + id.String() + "] "
    31  }
    32  
    33  // Info logs and adds a trace event if channelz is on.
    34  func Info(l grpclog.DepthLoggerV2, id *Identifier, args ...any) {
    35  	AddTraceEvent(l, id, 1, &TraceEventDesc{
    36  		Desc:     fmt.Sprint(args...),
    37  		Severity: CtInfo,
    38  	})
    39  }
    40  
    41  // Infof logs and adds a trace event if channelz is on.
    42  func Infof(l grpclog.DepthLoggerV2, id *Identifier, format string, args ...any) {
    43  	AddTraceEvent(l, id, 1, &TraceEventDesc{
    44  		Desc:     fmt.Sprintf(format, args...),
    45  		Severity: CtInfo,
    46  	})
    47  }
    48  
    49  // Warning logs and adds a trace event if channelz is on.
    50  func Warning(l grpclog.DepthLoggerV2, id *Identifier, args ...any) {
    51  	AddTraceEvent(l, id, 1, &TraceEventDesc{
    52  		Desc:     fmt.Sprint(args...),
    53  		Severity: CtWarning,
    54  	})
    55  }
    56  
    57  // Warningf logs and adds a trace event if channelz is on.
    58  func Warningf(l grpclog.DepthLoggerV2, id *Identifier, format string, args ...any) {
    59  	AddTraceEvent(l, id, 1, &TraceEventDesc{
    60  		Desc:     fmt.Sprintf(format, args...),
    61  		Severity: CtWarning,
    62  	})
    63  }
    64  
    65  // Error logs and adds a trace event if channelz is on.
    66  func Error(l grpclog.DepthLoggerV2, id *Identifier, args ...any) {
    67  	AddTraceEvent(l, id, 1, &TraceEventDesc{
    68  		Desc:     fmt.Sprint(args...),
    69  		Severity: CtError,
    70  	})
    71  }
    72  
    73  // Errorf logs and adds a trace event if channelz is on.
    74  func Errorf(l grpclog.DepthLoggerV2, id *Identifier, format string, args ...any) {
    75  	AddTraceEvent(l, id, 1, &TraceEventDesc{
    76  		Desc:     fmt.Sprintf(format, args...),
    77  		Severity: CtError,
    78  	})
    79  }