blob: 8c8e19fce1d5262cbb5ba245bcec8e24f957f7ec [file] [log] [blame]
amit.ghosh258d14c2020-10-02 15:13:38 +02001/*
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 grpclog (internal) defines depth logging for grpc.
20package grpclog
21
22// Logger is the logger used for the non-depth log functions.
23var Logger LoggerV2
24
25// DepthLogger is the logger used for the depth log functions.
26var DepthLogger DepthLoggerV2
27
28// InfoDepth logs to the INFO log at the specified depth.
29func InfoDepth(depth int, args ...interface{}) {
30 if DepthLogger != nil {
31 DepthLogger.InfoDepth(depth, args...)
32 } else {
33 Logger.Info(args...)
34 }
35}
36
37// WarningDepth logs to the WARNING log at the specified depth.
38func WarningDepth(depth int, args ...interface{}) {
39 if DepthLogger != nil {
40 DepthLogger.WarningDepth(depth, args...)
41 } else {
42 Logger.Warning(args...)
43 }
44}
45
46// ErrorDepth logs to the ERROR log at the specified depth.
47func ErrorDepth(depth int, args ...interface{}) {
48 if DepthLogger != nil {
49 DepthLogger.ErrorDepth(depth, args...)
50 } else {
51 Logger.Error(args...)
52 }
53}
54
55// FatalDepth logs to the FATAL log at the specified depth.
56func FatalDepth(depth int, args ...interface{}) {
57 if DepthLogger != nil {
58 DepthLogger.FatalDepth(depth, args...)
59 } else {
60 Logger.Fatal(args...)
61 }
62}
63
64// LoggerV2 does underlying logging work for grpclog.
65// This is a copy of the LoggerV2 defined in the external grpclog package. It
66// is defined here to avoid a circular dependency.
67type LoggerV2 interface {
68 // Info logs to INFO log. Arguments are handled in the manner of fmt.Print.
69 Info(args ...interface{})
70 // Infoln logs to INFO log. Arguments are handled in the manner of fmt.Println.
71 Infoln(args ...interface{})
72 // Infof logs to INFO log. Arguments are handled in the manner of fmt.Printf.
73 Infof(format string, args ...interface{})
74 // Warning logs to WARNING log. Arguments are handled in the manner of fmt.Print.
75 Warning(args ...interface{})
76 // Warningln logs to WARNING log. Arguments are handled in the manner of fmt.Println.
77 Warningln(args ...interface{})
78 // Warningf logs to WARNING log. Arguments are handled in the manner of fmt.Printf.
79 Warningf(format string, args ...interface{})
80 // Error logs to ERROR log. Arguments are handled in the manner of fmt.Print.
81 Error(args ...interface{})
82 // Errorln logs to ERROR log. Arguments are handled in the manner of fmt.Println.
83 Errorln(args ...interface{})
84 // Errorf logs to ERROR log. Arguments are handled in the manner of fmt.Printf.
85 Errorf(format string, args ...interface{})
86 // Fatal logs to ERROR log. Arguments are handled in the manner of fmt.Print.
87 // gRPC ensures that all Fatal logs will exit with os.Exit(1).
88 // Implementations may also call os.Exit() with a non-zero exit code.
89 Fatal(args ...interface{})
90 // Fatalln logs to ERROR log. Arguments are handled in the manner of fmt.Println.
91 // gRPC ensures that all Fatal logs will exit with os.Exit(1).
92 // Implementations may also call os.Exit() with a non-zero exit code.
93 Fatalln(args ...interface{})
94 // Fatalf logs to ERROR log. Arguments are handled in the manner of fmt.Printf.
95 // gRPC ensures that all Fatal logs will exit with os.Exit(1).
96 // Implementations may also call os.Exit() with a non-zero exit code.
97 Fatalf(format string, args ...interface{})
98 // V reports whether verbosity level l is at least the requested verbose level.
99 V(l int) bool
100}
101
102// DepthLoggerV2 logs at a specified call frame. If a LoggerV2 also implements
103// DepthLoggerV2, the below functions will be called with the appropriate stack
104// depth set for trivial functions the logger may ignore.
105// This is a copy of the DepthLoggerV2 defined in the external grpclog package.
106// It is defined here to avoid a circular dependency.
107//
108// This API is EXPERIMENTAL.
109type DepthLoggerV2 interface {
110 // InfoDepth logs to INFO log at the specified depth. Arguments are handled in the manner of fmt.Print.
111 InfoDepth(depth int, args ...interface{})
112 // WarningDepth logs to WARNING log at the specified depth. Arguments are handled in the manner of fmt.Print.
113 WarningDepth(depth int, args ...interface{})
114 // ErrorDetph logs to ERROR log at the specified depth. Arguments are handled in the manner of fmt.Print.
115 ErrorDepth(depth int, args ...interface{})
116 // FatalDepth logs to FATAL log at the specified depth. Arguments are handled in the manner of fmt.Print.
117 FatalDepth(depth int, args ...interface{})
118}