Matteo Scandolo | a6a3aee | 2019-11-26 13:30:14 -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 | // |
| 21 | // All logs in transport and grpclb packages only go to verbose level 2. |
| 22 | // All logs in other packages in grpc are logged in spite of the verbosity level. |
| 23 | // |
| 24 | // In the default logger, |
| 25 | // severity level can be set by environment variable GRPC_GO_LOG_SEVERITY_LEVEL, |
| 26 | // verbosity level can be set by GRPC_GO_LOG_VERBOSITY_LEVEL. |
| 27 | package grpclog // import "google.golang.org/grpc/grpclog" |
| 28 | |
amit.ghosh | 258d14c | 2020-10-02 15:13:38 +0200 | [diff] [blame] | 29 | import ( |
| 30 | "os" |
Matteo Scandolo | a6a3aee | 2019-11-26 13:30:14 -0700 | [diff] [blame] | 31 | |
amit.ghosh | 258d14c | 2020-10-02 15:13:38 +0200 | [diff] [blame] | 32 | "google.golang.org/grpc/internal/grpclog" |
| 33 | ) |
| 34 | |
| 35 | func init() { |
| 36 | SetLoggerV2(newLoggerV2()) |
| 37 | } |
Matteo Scandolo | a6a3aee | 2019-11-26 13:30:14 -0700 | [diff] [blame] | 38 | |
| 39 | // V reports whether verbosity level l is at least the requested verbose level. |
| 40 | func V(l int) bool { |
amit.ghosh | 258d14c | 2020-10-02 15:13:38 +0200 | [diff] [blame] | 41 | return grpclog.Logger.V(l) |
Matteo Scandolo | a6a3aee | 2019-11-26 13:30:14 -0700 | [diff] [blame] | 42 | } |
| 43 | |
| 44 | // Info logs to the INFO log. |
| 45 | func Info(args ...interface{}) { |
amit.ghosh | 258d14c | 2020-10-02 15:13:38 +0200 | [diff] [blame] | 46 | grpclog.Logger.Info(args...) |
Matteo Scandolo | a6a3aee | 2019-11-26 13:30:14 -0700 | [diff] [blame] | 47 | } |
| 48 | |
| 49 | // Infof logs to the INFO log. Arguments are handled in the manner of fmt.Printf. |
| 50 | func Infof(format string, args ...interface{}) { |
amit.ghosh | 258d14c | 2020-10-02 15:13:38 +0200 | [diff] [blame] | 51 | grpclog.Logger.Infof(format, args...) |
Matteo Scandolo | a6a3aee | 2019-11-26 13:30:14 -0700 | [diff] [blame] | 52 | } |
| 53 | |
| 54 | // Infoln logs to the INFO log. Arguments are handled in the manner of fmt.Println. |
| 55 | func Infoln(args ...interface{}) { |
amit.ghosh | 258d14c | 2020-10-02 15:13:38 +0200 | [diff] [blame] | 56 | grpclog.Logger.Infoln(args...) |
Matteo Scandolo | a6a3aee | 2019-11-26 13:30:14 -0700 | [diff] [blame] | 57 | } |
| 58 | |
| 59 | // Warning logs to the WARNING log. |
| 60 | func Warning(args ...interface{}) { |
amit.ghosh | 258d14c | 2020-10-02 15:13:38 +0200 | [diff] [blame] | 61 | grpclog.Logger.Warning(args...) |
Matteo Scandolo | a6a3aee | 2019-11-26 13:30:14 -0700 | [diff] [blame] | 62 | } |
| 63 | |
| 64 | // Warningf logs to the WARNING log. Arguments are handled in the manner of fmt.Printf. |
| 65 | func Warningf(format string, args ...interface{}) { |
amit.ghosh | 258d14c | 2020-10-02 15:13:38 +0200 | [diff] [blame] | 66 | grpclog.Logger.Warningf(format, args...) |
Matteo Scandolo | a6a3aee | 2019-11-26 13:30:14 -0700 | [diff] [blame] | 67 | } |
| 68 | |
| 69 | // Warningln logs to the WARNING log. Arguments are handled in the manner of fmt.Println. |
| 70 | func Warningln(args ...interface{}) { |
amit.ghosh | 258d14c | 2020-10-02 15:13:38 +0200 | [diff] [blame] | 71 | grpclog.Logger.Warningln(args...) |
Matteo Scandolo | a6a3aee | 2019-11-26 13:30:14 -0700 | [diff] [blame] | 72 | } |
| 73 | |
| 74 | // Error logs to the ERROR log. |
| 75 | func Error(args ...interface{}) { |
amit.ghosh | 258d14c | 2020-10-02 15:13:38 +0200 | [diff] [blame] | 76 | grpclog.Logger.Error(args...) |
Matteo Scandolo | a6a3aee | 2019-11-26 13:30:14 -0700 | [diff] [blame] | 77 | } |
| 78 | |
| 79 | // Errorf logs to the ERROR log. Arguments are handled in the manner of fmt.Printf. |
| 80 | func Errorf(format string, args ...interface{}) { |
amit.ghosh | 258d14c | 2020-10-02 15:13:38 +0200 | [diff] [blame] | 81 | grpclog.Logger.Errorf(format, args...) |
Matteo Scandolo | a6a3aee | 2019-11-26 13:30:14 -0700 | [diff] [blame] | 82 | } |
| 83 | |
| 84 | // Errorln logs to the ERROR log. Arguments are handled in the manner of fmt.Println. |
| 85 | func Errorln(args ...interface{}) { |
amit.ghosh | 258d14c | 2020-10-02 15:13:38 +0200 | [diff] [blame] | 86 | grpclog.Logger.Errorln(args...) |
Matteo Scandolo | a6a3aee | 2019-11-26 13:30:14 -0700 | [diff] [blame] | 87 | } |
| 88 | |
| 89 | // Fatal logs to the FATAL log. Arguments are handled in the manner of fmt.Print. |
| 90 | // It calls os.Exit() with exit code 1. |
| 91 | func Fatal(args ...interface{}) { |
amit.ghosh | 258d14c | 2020-10-02 15:13:38 +0200 | [diff] [blame] | 92 | grpclog.Logger.Fatal(args...) |
Matteo Scandolo | a6a3aee | 2019-11-26 13:30:14 -0700 | [diff] [blame] | 93 | // Make sure fatal logs will exit. |
| 94 | os.Exit(1) |
| 95 | } |
| 96 | |
| 97 | // Fatalf logs to the FATAL log. Arguments are handled in the manner of fmt.Printf. |
Arjun E K | 57a7fcb | 2020-01-30 06:44:45 +0000 | [diff] [blame] | 98 | // It calls os.Exit() with exit code 1. |
Matteo Scandolo | a6a3aee | 2019-11-26 13:30:14 -0700 | [diff] [blame] | 99 | func Fatalf(format string, args ...interface{}) { |
amit.ghosh | 258d14c | 2020-10-02 15:13:38 +0200 | [diff] [blame] | 100 | grpclog.Logger.Fatalf(format, args...) |
Matteo Scandolo | a6a3aee | 2019-11-26 13:30:14 -0700 | [diff] [blame] | 101 | // Make sure fatal logs will exit. |
| 102 | os.Exit(1) |
| 103 | } |
| 104 | |
| 105 | // Fatalln logs to the FATAL log. Arguments are handled in the manner of fmt.Println. |
| 106 | // It calle os.Exit()) with exit code 1. |
| 107 | func Fatalln(args ...interface{}) { |
amit.ghosh | 258d14c | 2020-10-02 15:13:38 +0200 | [diff] [blame] | 108 | grpclog.Logger.Fatalln(args...) |
Matteo Scandolo | a6a3aee | 2019-11-26 13:30:14 -0700 | [diff] [blame] | 109 | // Make sure fatal logs will exit. |
| 110 | os.Exit(1) |
| 111 | } |
| 112 | |
| 113 | // Print prints to the logger. Arguments are handled in the manner of fmt.Print. |
| 114 | // |
| 115 | // Deprecated: use Info. |
| 116 | func Print(args ...interface{}) { |
amit.ghosh | 258d14c | 2020-10-02 15:13:38 +0200 | [diff] [blame] | 117 | grpclog.Logger.Info(args...) |
Matteo Scandolo | a6a3aee | 2019-11-26 13:30:14 -0700 | [diff] [blame] | 118 | } |
| 119 | |
| 120 | // Printf prints to the logger. Arguments are handled in the manner of fmt.Printf. |
| 121 | // |
| 122 | // Deprecated: use Infof. |
| 123 | func Printf(format string, args ...interface{}) { |
amit.ghosh | 258d14c | 2020-10-02 15:13:38 +0200 | [diff] [blame] | 124 | grpclog.Logger.Infof(format, args...) |
Matteo Scandolo | a6a3aee | 2019-11-26 13:30:14 -0700 | [diff] [blame] | 125 | } |
| 126 | |
| 127 | // Println prints to the logger. Arguments are handled in the manner of fmt.Println. |
| 128 | // |
| 129 | // Deprecated: use Infoln. |
| 130 | func Println(args ...interface{}) { |
amit.ghosh | 258d14c | 2020-10-02 15:13:38 +0200 | [diff] [blame] | 131 | grpclog.Logger.Infoln(args...) |
Matteo Scandolo | a6a3aee | 2019-11-26 13:30:14 -0700 | [diff] [blame] | 132 | } |