google.golang.org/grpc@v1.72.2/grpclog/grpclog.go (about)

     1  /*
     2   *
     3   * Copyright 2017 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 grpclog defines logging for grpc.
    20  //
    21  // In the default logger, severity level can be set by environment variable
    22  // GRPC_GO_LOG_SEVERITY_LEVEL, verbosity level can be set by
    23  // GRPC_GO_LOG_VERBOSITY_LEVEL.
    24  package grpclog
    25  
    26  import (
    27  	"os"
    28  
    29  	"google.golang.org/grpc/grpclog/internal"
    30  )
    31  
    32  func init() {
    33  	SetLoggerV2(newLoggerV2())
    34  }
    35  
    36  // V reports whether verbosity level l is at least the requested verbose level.
    37  func V(l int) bool {
    38  	return internal.LoggerV2Impl.V(l)
    39  }
    40  
    41  // Info logs to the INFO log.
    42  func Info(args ...any) {
    43  	internal.LoggerV2Impl.Info(args...)
    44  }
    45  
    46  // Infof logs to the INFO log. Arguments are handled in the manner of fmt.Printf.
    47  func Infof(format string, args ...any) {
    48  	internal.LoggerV2Impl.Infof(format, args...)
    49  }
    50  
    51  // Infoln logs to the INFO log. Arguments are handled in the manner of fmt.Println.
    52  func Infoln(args ...any) {
    53  	internal.LoggerV2Impl.Infoln(args...)
    54  }
    55  
    56  // Warning logs to the WARNING log.
    57  func Warning(args ...any) {
    58  	internal.LoggerV2Impl.Warning(args...)
    59  }
    60  
    61  // Warningf logs to the WARNING log. Arguments are handled in the manner of fmt.Printf.
    62  func Warningf(format string, args ...any) {
    63  	internal.LoggerV2Impl.Warningf(format, args...)
    64  }
    65  
    66  // Warningln logs to the WARNING log. Arguments are handled in the manner of fmt.Println.
    67  func Warningln(args ...any) {
    68  	internal.LoggerV2Impl.Warningln(args...)
    69  }
    70  
    71  // Error logs to the ERROR log.
    72  func Error(args ...any) {
    73  	internal.LoggerV2Impl.Error(args...)
    74  }
    75  
    76  // Errorf logs to the ERROR log. Arguments are handled in the manner of fmt.Printf.
    77  func Errorf(format string, args ...any) {
    78  	internal.LoggerV2Impl.Errorf(format, args...)
    79  }
    80  
    81  // Errorln logs to the ERROR log. Arguments are handled in the manner of fmt.Println.
    82  func Errorln(args ...any) {
    83  	internal.LoggerV2Impl.Errorln(args...)
    84  }
    85  
    86  // Fatal logs to the FATAL log. Arguments are handled in the manner of fmt.Print.
    87  // It calls os.Exit() with exit code 1.
    88  func Fatal(args ...any) {
    89  	internal.LoggerV2Impl.Fatal(args...)
    90  	// Make sure fatal logs will exit.
    91  	os.Exit(1)
    92  }
    93  
    94  // Fatalf logs to the FATAL log. Arguments are handled in the manner of fmt.Printf.
    95  // It calls os.Exit() with exit code 1.
    96  func Fatalf(format string, args ...any) {
    97  	internal.LoggerV2Impl.Fatalf(format, args...)
    98  	// Make sure fatal logs will exit.
    99  	os.Exit(1)
   100  }
   101  
   102  // Fatalln logs to the FATAL log. Arguments are handled in the manner of fmt.Println.
   103  // It calls os.Exit() with exit code 1.
   104  func Fatalln(args ...any) {
   105  	internal.LoggerV2Impl.Fatalln(args...)
   106  	// Make sure fatal logs will exit.
   107  	os.Exit(1)
   108  }
   109  
   110  // Print prints to the logger. Arguments are handled in the manner of fmt.Print.
   111  //
   112  // Deprecated: use Info.
   113  func Print(args ...any) {
   114  	internal.LoggerV2Impl.Info(args...)
   115  }
   116  
   117  // Printf prints to the logger. Arguments are handled in the manner of fmt.Printf.
   118  //
   119  // Deprecated: use Infof.
   120  func Printf(format string, args ...any) {
   121  	internal.LoggerV2Impl.Infof(format, args...)
   122  }
   123  
   124  // Println prints to the logger. Arguments are handled in the manner of fmt.Println.
   125  //
   126  // Deprecated: use Infoln.
   127  func Println(args ...any) {
   128  	internal.LoggerV2Impl.Infoln(args...)
   129  }
   130  
   131  // InfoDepth logs to the INFO log at the specified depth.
   132  //
   133  // # Experimental
   134  //
   135  // Notice: This API is EXPERIMENTAL and may be changed or removed in a
   136  // later release.
   137  func InfoDepth(depth int, args ...any) {
   138  	if internal.DepthLoggerV2Impl != nil {
   139  		internal.DepthLoggerV2Impl.InfoDepth(depth, args...)
   140  	} else {
   141  		internal.LoggerV2Impl.Infoln(args...)
   142  	}
   143  }
   144  
   145  // WarningDepth logs to the WARNING log at the specified depth.
   146  //
   147  // # Experimental
   148  //
   149  // Notice: This API is EXPERIMENTAL and may be changed or removed in a
   150  // later release.
   151  func WarningDepth(depth int, args ...any) {
   152  	if internal.DepthLoggerV2Impl != nil {
   153  		internal.DepthLoggerV2Impl.WarningDepth(depth, args...)
   154  	} else {
   155  		internal.LoggerV2Impl.Warningln(args...)
   156  	}
   157  }
   158  
   159  // ErrorDepth logs to the ERROR log at the specified depth.
   160  //
   161  // # Experimental
   162  //
   163  // Notice: This API is EXPERIMENTAL and may be changed or removed in a
   164  // later release.
   165  func ErrorDepth(depth int, args ...any) {
   166  	if internal.DepthLoggerV2Impl != nil {
   167  		internal.DepthLoggerV2Impl.ErrorDepth(depth, args...)
   168  	} else {
   169  		internal.LoggerV2Impl.Errorln(args...)
   170  	}
   171  }
   172  
   173  // FatalDepth logs to the FATAL log at the specified depth.
   174  //
   175  // # Experimental
   176  //
   177  // Notice: This API is EXPERIMENTAL and may be changed or removed in a
   178  // later release.
   179  func FatalDepth(depth int, args ...any) {
   180  	if internal.DepthLoggerV2Impl != nil {
   181  		internal.DepthLoggerV2Impl.FatalDepth(depth, args...)
   182  	} else {
   183  		internal.LoggerV2Impl.Fatalln(args...)
   184  	}
   185  	os.Exit(1)
   186  }