| Scott Baker | 2c1c482 | 2019-10-16 11:02:41 -0700 | [diff] [blame] | 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 | // |
| Abhay Kumar | 40252eb | 2025-10-13 13:25:53 +0000 | [diff] [blame^] | 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 |
| Scott Baker | 2c1c482 | 2019-10-16 11:02:41 -0700 | [diff] [blame] | 25 | |
| Abhay Kumar | 40252eb | 2025-10-13 13:25:53 +0000 | [diff] [blame^] | 26 | import ( |
| 27 | "os" |
| Scott Baker | 2c1c482 | 2019-10-16 11:02:41 -0700 | [diff] [blame] | 28 | |
| Abhay Kumar | 40252eb | 2025-10-13 13:25:53 +0000 | [diff] [blame^] | 29 | "google.golang.org/grpc/grpclog/internal" |
| 30 | ) |
| 31 | |
| 32 | func init() { |
| 33 | SetLoggerV2(newLoggerV2()) |
| 34 | } |
| Scott Baker | 2c1c482 | 2019-10-16 11:02:41 -0700 | [diff] [blame] | 35 | |
| 36 | // V reports whether verbosity level l is at least the requested verbose level. |
| 37 | func V(l int) bool { |
| Abhay Kumar | 40252eb | 2025-10-13 13:25:53 +0000 | [diff] [blame^] | 38 | return internal.LoggerV2Impl.V(l) |
| Scott Baker | 2c1c482 | 2019-10-16 11:02:41 -0700 | [diff] [blame] | 39 | } |
| 40 | |
| 41 | // Info logs to the INFO log. |
| Abhay Kumar | 40252eb | 2025-10-13 13:25:53 +0000 | [diff] [blame^] | 42 | func Info(args ...any) { |
| 43 | internal.LoggerV2Impl.Info(args...) |
| Scott Baker | 2c1c482 | 2019-10-16 11:02:41 -0700 | [diff] [blame] | 44 | } |
| 45 | |
| 46 | // Infof logs to the INFO log. Arguments are handled in the manner of fmt.Printf. |
| Abhay Kumar | 40252eb | 2025-10-13 13:25:53 +0000 | [diff] [blame^] | 47 | func Infof(format string, args ...any) { |
| 48 | internal.LoggerV2Impl.Infof(format, args...) |
| Scott Baker | 2c1c482 | 2019-10-16 11:02:41 -0700 | [diff] [blame] | 49 | } |
| 50 | |
| 51 | // Infoln logs to the INFO log. Arguments are handled in the manner of fmt.Println. |
| Abhay Kumar | 40252eb | 2025-10-13 13:25:53 +0000 | [diff] [blame^] | 52 | func Infoln(args ...any) { |
| 53 | internal.LoggerV2Impl.Infoln(args...) |
| Scott Baker | 2c1c482 | 2019-10-16 11:02:41 -0700 | [diff] [blame] | 54 | } |
| 55 | |
| 56 | // Warning logs to the WARNING log. |
| Abhay Kumar | 40252eb | 2025-10-13 13:25:53 +0000 | [diff] [blame^] | 57 | func Warning(args ...any) { |
| 58 | internal.LoggerV2Impl.Warning(args...) |
| Scott Baker | 2c1c482 | 2019-10-16 11:02:41 -0700 | [diff] [blame] | 59 | } |
| 60 | |
| 61 | // Warningf logs to the WARNING log. Arguments are handled in the manner of fmt.Printf. |
| Abhay Kumar | 40252eb | 2025-10-13 13:25:53 +0000 | [diff] [blame^] | 62 | func Warningf(format string, args ...any) { |
| 63 | internal.LoggerV2Impl.Warningf(format, args...) |
| Scott Baker | 2c1c482 | 2019-10-16 11:02:41 -0700 | [diff] [blame] | 64 | } |
| 65 | |
| 66 | // Warningln logs to the WARNING log. Arguments are handled in the manner of fmt.Println. |
| Abhay Kumar | 40252eb | 2025-10-13 13:25:53 +0000 | [diff] [blame^] | 67 | func Warningln(args ...any) { |
| 68 | internal.LoggerV2Impl.Warningln(args...) |
| Scott Baker | 2c1c482 | 2019-10-16 11:02:41 -0700 | [diff] [blame] | 69 | } |
| 70 | |
| 71 | // Error logs to the ERROR log. |
| Abhay Kumar | 40252eb | 2025-10-13 13:25:53 +0000 | [diff] [blame^] | 72 | func Error(args ...any) { |
| 73 | internal.LoggerV2Impl.Error(args...) |
| Scott Baker | 2c1c482 | 2019-10-16 11:02:41 -0700 | [diff] [blame] | 74 | } |
| 75 | |
| 76 | // Errorf logs to the ERROR log. Arguments are handled in the manner of fmt.Printf. |
| Abhay Kumar | 40252eb | 2025-10-13 13:25:53 +0000 | [diff] [blame^] | 77 | func Errorf(format string, args ...any) { |
| 78 | internal.LoggerV2Impl.Errorf(format, args...) |
| Scott Baker | 2c1c482 | 2019-10-16 11:02:41 -0700 | [diff] [blame] | 79 | } |
| 80 | |
| 81 | // Errorln logs to the ERROR log. Arguments are handled in the manner of fmt.Println. |
| Abhay Kumar | 40252eb | 2025-10-13 13:25:53 +0000 | [diff] [blame^] | 82 | func Errorln(args ...any) { |
| 83 | internal.LoggerV2Impl.Errorln(args...) |
| Scott Baker | 2c1c482 | 2019-10-16 11:02:41 -0700 | [diff] [blame] | 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. |
| Abhay Kumar | 40252eb | 2025-10-13 13:25:53 +0000 | [diff] [blame^] | 88 | func Fatal(args ...any) { |
| 89 | internal.LoggerV2Impl.Fatal(args...) |
| Scott Baker | 2c1c482 | 2019-10-16 11:02:41 -0700 | [diff] [blame] | 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. |
| khenaidoo | 2672188 | 2021-08-11 17:42:52 -0400 | [diff] [blame] | 95 | // It calls os.Exit() with exit code 1. |
| Abhay Kumar | 40252eb | 2025-10-13 13:25:53 +0000 | [diff] [blame^] | 96 | func Fatalf(format string, args ...any) { |
| 97 | internal.LoggerV2Impl.Fatalf(format, args...) |
| Scott Baker | 2c1c482 | 2019-10-16 11:02:41 -0700 | [diff] [blame] | 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. |
| Abhay Kumar | 40252eb | 2025-10-13 13:25:53 +0000 | [diff] [blame^] | 103 | // It calls os.Exit() with exit code 1. |
| 104 | func Fatalln(args ...any) { |
| 105 | internal.LoggerV2Impl.Fatalln(args...) |
| Scott Baker | 2c1c482 | 2019-10-16 11:02:41 -0700 | [diff] [blame] | 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. |
| Abhay Kumar | 40252eb | 2025-10-13 13:25:53 +0000 | [diff] [blame^] | 113 | func Print(args ...any) { |
| 114 | internal.LoggerV2Impl.Info(args...) |
| Scott Baker | 2c1c482 | 2019-10-16 11:02:41 -0700 | [diff] [blame] | 115 | } |
| 116 | |
| 117 | // Printf prints to the logger. Arguments are handled in the manner of fmt.Printf. |
| 118 | // |
| 119 | // Deprecated: use Infof. |
| Abhay Kumar | 40252eb | 2025-10-13 13:25:53 +0000 | [diff] [blame^] | 120 | func Printf(format string, args ...any) { |
| 121 | internal.LoggerV2Impl.Infof(format, args...) |
| Scott Baker | 2c1c482 | 2019-10-16 11:02:41 -0700 | [diff] [blame] | 122 | } |
| 123 | |
| 124 | // Println prints to the logger. Arguments are handled in the manner of fmt.Println. |
| 125 | // |
| 126 | // Deprecated: use Infoln. |
| Abhay Kumar | 40252eb | 2025-10-13 13:25:53 +0000 | [diff] [blame^] | 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) |
| Scott Baker | 2c1c482 | 2019-10-16 11:02:41 -0700 | [diff] [blame] | 186 | } |