istio.io/istio@v0.0.0-20240520182934-d79c90f27776/pkg/log/default.go (about)

     1  // Copyright 2017 Istio Authors
     2  //
     3  // Licensed under the Apache License, Version 2.0 (the "License");
     4  // you may not use this file except in compliance with the License.
     5  // You may obtain a copy of the License at
     6  //
     7  //     http://www.apache.org/licenses/LICENSE-2.0
     8  //
     9  // Unless required by applicable law or agreed to in writing, software
    10  // distributed under the License is distributed on an "AS IS" BASIS,
    11  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    12  // See the License for the specific language governing permissions and
    13  // limitations under the License.
    14  
    15  package log
    16  
    17  // These functions enable logging using a global Scope. See scope.go for usage information.
    18  
    19  func registerDefaultScopes() (defaults *Scope, grpc *Scope) {
    20  	return registerScope(DefaultScopeName, "Unscoped logging messages.", 1),
    21  		registerScope(GrpcScopeName, "logs from gRPC", 3)
    22  }
    23  
    24  var defaultScope, grpcScope = registerDefaultScopes()
    25  
    26  // Fatal outputs a message at fatal level.
    27  func Fatal(fields any) {
    28  	defaultScope.Fatal(fields)
    29  }
    30  
    31  // Fatalf uses fmt.Sprintf to construct and log a message at fatal level.
    32  func Fatalf(format string, args ...any) {
    33  	defaultScope.Fatalf(format, args...)
    34  }
    35  
    36  // FatalEnabled returns whether output of messages using this scope is currently enabled for fatal-level output.
    37  func FatalEnabled() bool {
    38  	return defaultScope.FatalEnabled()
    39  }
    40  
    41  // Error outputs a message at error level.
    42  func Error(fields any) {
    43  	defaultScope.Error(fields)
    44  }
    45  
    46  // Errorf uses fmt.Sprintf to construct and log a message at error level.
    47  func Errorf(format string, args ...any) {
    48  	defaultScope.Errorf(format, args...)
    49  }
    50  
    51  // ErrorEnabled returns whether output of messages using this scope is currently enabled for error-level output.
    52  func ErrorEnabled() bool {
    53  	return defaultScope.ErrorEnabled()
    54  }
    55  
    56  // Warn outputs a message at warn level.
    57  func Warn(fields any) {
    58  	defaultScope.Warn(fields)
    59  }
    60  
    61  // Warnf uses fmt.Sprintf to construct and log a message at warn level.
    62  func Warnf(format string, args ...any) {
    63  	defaultScope.Warnf(format, args...)
    64  }
    65  
    66  // WarnEnabled returns whether output of messages using this scope is currently enabled for warn-level output.
    67  func WarnEnabled() bool {
    68  	return defaultScope.WarnEnabled()
    69  }
    70  
    71  // Info outputs a message at info level.
    72  func Info(fields any) {
    73  	defaultScope.Info(fields)
    74  }
    75  
    76  // Infof uses fmt.Sprintf to construct and log a message at info level.
    77  func Infof(format string, args ...any) {
    78  	defaultScope.Infof(format, args...)
    79  }
    80  
    81  // InfoEnabled returns whether output of messages using this scope is currently enabled for info-level output.
    82  func InfoEnabled() bool {
    83  	return defaultScope.InfoEnabled()
    84  }
    85  
    86  // Debug outputs a message at debug level.
    87  func Debug(fields any) {
    88  	defaultScope.Debug(fields)
    89  }
    90  
    91  // Debugf uses fmt.Sprintf to construct and log a message at debug level.
    92  func Debugf(format string, args ...any) {
    93  	defaultScope.Debugf(format, args...)
    94  }
    95  
    96  // DebugEnabled returns whether output of messages using this scope is currently enabled for debug-level output.
    97  func DebugEnabled() bool {
    98  	return defaultScope.DebugEnabled()
    99  }
   100  
   101  // WithLabels adds a key-value pairs to the labels in s. The key must be a string, while the value may be any type.
   102  // It returns a copy of the default scope, with the labels added.
   103  func WithLabels(kvlist ...any) *Scope {
   104  	return defaultScope.WithLabels(kvlist...)
   105  }