aboutsummaryrefslogtreecommitdiffhomepage
path: root/vendor/google.golang.org/grpc/grpclog
diff options
context:
space:
mode:
Diffstat (limited to 'vendor/google.golang.org/grpc/grpclog')
-rw-r--r--vendor/google.golang.org/grpc/grpclog/grpclog.go123
-rw-r--r--vendor/google.golang.org/grpc/grpclog/logger.go83
-rw-r--r--vendor/google.golang.org/grpc/grpclog/loggerv2.go195
3 files changed, 401 insertions, 0 deletions
diff --git a/vendor/google.golang.org/grpc/grpclog/grpclog.go b/vendor/google.golang.org/grpc/grpclog/grpclog.go
new file mode 100644
index 0000000..16a7d88
--- /dev/null
+++ b/vendor/google.golang.org/grpc/grpclog/grpclog.go
@@ -0,0 +1,123 @@
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 package 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.
27package grpclog // import "google.golang.org/grpc/grpclog"
28
29import "os"
30
31var logger = newLoggerV2()
32
33// V reports whether verbosity level l is at least the requested verbose level.
34func V(l int) bool {
35 return logger.V(l)
36}
37
38// Info logs to the INFO log.
39func Info(args ...interface{}) {
40 logger.Info(args...)
41}
42
43// Infof logs to the INFO log. Arguments are handled in the manner of fmt.Printf.
44func Infof(format string, args ...interface{}) {
45 logger.Infof(format, args...)
46}
47
48// Infoln logs to the INFO log. Arguments are handled in the manner of fmt.Println.
49func Infoln(args ...interface{}) {
50 logger.Infoln(args...)
51}
52
53// Warning logs to the WARNING log.
54func Warning(args ...interface{}) {
55 logger.Warning(args...)
56}
57
58// Warningf logs to the WARNING log. Arguments are handled in the manner of fmt.Printf.
59func Warningf(format string, args ...interface{}) {
60 logger.Warningf(format, args...)
61}
62
63// Warningln logs to the WARNING log. Arguments are handled in the manner of fmt.Println.
64func Warningln(args ...interface{}) {
65 logger.Warningln(args...)
66}
67
68// Error logs to the ERROR log.
69func Error(args ...interface{}) {
70 logger.Error(args...)
71}
72
73// Errorf logs to the ERROR log. Arguments are handled in the manner of fmt.Printf.
74func Errorf(format string, args ...interface{}) {
75 logger.Errorf(format, args...)
76}
77
78// Errorln logs to the ERROR log. Arguments are handled in the manner of fmt.Println.
79func Errorln(args ...interface{}) {
80 logger.Errorln(args...)
81}
82
83// Fatal logs to the FATAL log. Arguments are handled in the manner of fmt.Print.
84// It calls os.Exit() with exit code 1.
85func Fatal(args ...interface{}) {
86 logger.Fatal(args...)
87 // Make sure fatal logs will exit.
88 os.Exit(1)
89}
90
91// Fatalf logs to the FATAL log. Arguments are handled in the manner of fmt.Printf.
92// It calles os.Exit() with exit code 1.
93func Fatalf(format string, args ...interface{}) {
94 logger.Fatalf(format, args...)
95 // Make sure fatal logs will exit.
96 os.Exit(1)
97}
98
99// Fatalln logs to the FATAL log. Arguments are handled in the manner of fmt.Println.
100// It calle os.Exit()) with exit code 1.
101func Fatalln(args ...interface{}) {
102 logger.Fatalln(args...)
103 // Make sure fatal logs will exit.
104 os.Exit(1)
105}
106
107// Print prints to the logger. Arguments are handled in the manner of fmt.Print.
108// Deprecated: use Info.
109func Print(args ...interface{}) {
110 logger.Info(args...)
111}
112
113// Printf prints to the logger. Arguments are handled in the manner of fmt.Printf.
114// Deprecated: use Infof.
115func Printf(format string, args ...interface{}) {
116 logger.Infof(format, args...)
117}
118
119// Println prints to the logger. Arguments are handled in the manner of fmt.Println.
120// Deprecated: use Infoln.
121func Println(args ...interface{}) {
122 logger.Infoln(args...)
123}
diff --git a/vendor/google.golang.org/grpc/grpclog/logger.go b/vendor/google.golang.org/grpc/grpclog/logger.go
new file mode 100644
index 0000000..d03b239
--- /dev/null
+++ b/vendor/google.golang.org/grpc/grpclog/logger.go
@@ -0,0 +1,83 @@
1/*
2 *
3 * Copyright 2015 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
19package grpclog
20
21// Logger mimics golang's standard Logger as an interface.
22// Deprecated: use LoggerV2.
23type Logger interface {
24 Fatal(args ...interface{})
25 Fatalf(format string, args ...interface{})
26 Fatalln(args ...interface{})
27 Print(args ...interface{})
28 Printf(format string, args ...interface{})
29 Println(args ...interface{})
30}
31
32// SetLogger sets the logger that is used in grpc. Call only from
33// init() functions.
34// Deprecated: use SetLoggerV2.
35func SetLogger(l Logger) {
36 logger = &loggerWrapper{Logger: l}
37}
38
39// loggerWrapper wraps Logger into a LoggerV2.
40type loggerWrapper struct {
41 Logger
42}
43
44func (g *loggerWrapper) Info(args ...interface{}) {
45 g.Logger.Print(args...)
46}
47
48func (g *loggerWrapper) Infoln(args ...interface{}) {
49 g.Logger.Println(args...)
50}
51
52func (g *loggerWrapper) Infof(format string, args ...interface{}) {
53 g.Logger.Printf(format, args...)
54}
55
56func (g *loggerWrapper) Warning(args ...interface{}) {
57 g.Logger.Print(args...)
58}
59
60func (g *loggerWrapper) Warningln(args ...interface{}) {
61 g.Logger.Println(args...)
62}
63
64func (g *loggerWrapper) Warningf(format string, args ...interface{}) {
65 g.Logger.Printf(format, args...)
66}
67
68func (g *loggerWrapper) Error(args ...interface{}) {
69 g.Logger.Print(args...)
70}
71
72func (g *loggerWrapper) Errorln(args ...interface{}) {
73 g.Logger.Println(args...)
74}
75
76func (g *loggerWrapper) Errorf(format string, args ...interface{}) {
77 g.Logger.Printf(format, args...)
78}
79
80func (g *loggerWrapper) V(l int) bool {
81 // Returns true for all verbose level.
82 return true
83}
diff --git a/vendor/google.golang.org/grpc/grpclog/loggerv2.go b/vendor/google.golang.org/grpc/grpclog/loggerv2.go
new file mode 100644
index 0000000..d493257
--- /dev/null
+++ b/vendor/google.golang.org/grpc/grpclog/loggerv2.go
@@ -0,0 +1,195 @@
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
19package grpclog
20
21import (
22 "io"
23 "io/ioutil"
24 "log"
25 "os"
26 "strconv"
27)
28
29// LoggerV2 does underlying logging work for grpclog.
30type LoggerV2 interface {
31 // Info logs to INFO log. Arguments are handled in the manner of fmt.Print.
32 Info(args ...interface{})
33 // Infoln logs to INFO log. Arguments are handled in the manner of fmt.Println.
34 Infoln(args ...interface{})
35 // Infof logs to INFO log. Arguments are handled in the manner of fmt.Printf.
36 Infof(format string, args ...interface{})
37 // Warning logs to WARNING log. Arguments are handled in the manner of fmt.Print.
38 Warning(args ...interface{})
39 // Warningln logs to WARNING log. Arguments are handled in the manner of fmt.Println.
40 Warningln(args ...interface{})
41 // Warningf logs to WARNING log. Arguments are handled in the manner of fmt.Printf.
42 Warningf(format string, args ...interface{})
43 // Error logs to ERROR log. Arguments are handled in the manner of fmt.Print.
44 Error(args ...interface{})
45 // Errorln logs to ERROR log. Arguments are handled in the manner of fmt.Println.
46 Errorln(args ...interface{})
47 // Errorf logs to ERROR log. Arguments are handled in the manner of fmt.Printf.
48 Errorf(format string, args ...interface{})
49 // Fatal logs to ERROR log. Arguments are handled in the manner of fmt.Print.
50 // gRPC ensures that all Fatal logs will exit with os.Exit(1).
51 // Implementations may also call os.Exit() with a non-zero exit code.
52 Fatal(args ...interface{})
53 // Fatalln logs to ERROR log. Arguments are handled in the manner of fmt.Println.
54 // gRPC ensures that all Fatal logs will exit with os.Exit(1).
55 // Implementations may also call os.Exit() with a non-zero exit code.
56 Fatalln(args ...interface{})
57 // Fatalf logs to ERROR log. Arguments are handled in the manner of fmt.Printf.
58 // gRPC ensures that all Fatal logs will exit with os.Exit(1).
59 // Implementations may also call os.Exit() with a non-zero exit code.
60 Fatalf(format string, args ...interface{})
61 // V reports whether verbosity level l is at least the requested verbose level.
62 V(l int) bool
63}
64
65// SetLoggerV2 sets logger that is used in grpc to a V2 logger.
66// Not mutex-protected, should be called before any gRPC functions.
67func SetLoggerV2(l LoggerV2) {
68 logger = l
69}
70
71const (
72 // infoLog indicates Info severity.
73 infoLog int = iota
74 // warningLog indicates Warning severity.
75 warningLog
76 // errorLog indicates Error severity.
77 errorLog
78 // fatalLog indicates Fatal severity.
79 fatalLog
80)
81
82// severityName contains the string representation of each severity.
83var severityName = []string{
84 infoLog: "INFO",
85 warningLog: "WARNING",
86 errorLog: "ERROR",
87 fatalLog: "FATAL",
88}
89
90// loggerT is the default logger used by grpclog.
91type loggerT struct {
92 m []*log.Logger
93 v int
94}
95
96// NewLoggerV2 creates a loggerV2 with the provided writers.
97// Fatal logs will be written to errorW, warningW, infoW, followed by exit(1).
98// Error logs will be written to errorW, warningW and infoW.
99// Warning logs will be written to warningW and infoW.
100// Info logs will be written to infoW.
101func NewLoggerV2(infoW, warningW, errorW io.Writer) LoggerV2 {
102 return NewLoggerV2WithVerbosity(infoW, warningW, errorW, 0)
103}
104
105// NewLoggerV2WithVerbosity creates a loggerV2 with the provided writers and
106// verbosity level.
107func NewLoggerV2WithVerbosity(infoW, warningW, errorW io.Writer, v int) LoggerV2 {
108 var m []*log.Logger
109 m = append(m, log.New(infoW, severityName[infoLog]+": ", log.LstdFlags))
110 m = append(m, log.New(io.MultiWriter(infoW, warningW), severityName[warningLog]+": ", log.LstdFlags))
111 ew := io.MultiWriter(infoW, warningW, errorW) // ew will be used for error and fatal.
112 m = append(m, log.New(ew, severityName[errorLog]+": ", log.LstdFlags))
113 m = append(m, log.New(ew, severityName[fatalLog]+": ", log.LstdFlags))
114 return &loggerT{m: m, v: v}
115}
116
117// newLoggerV2 creates a loggerV2 to be used as default logger.
118// All logs are written to stderr.
119func newLoggerV2() LoggerV2 {
120 errorW := ioutil.Discard
121 warningW := ioutil.Discard
122 infoW := ioutil.Discard
123
124 logLevel := os.Getenv("GRPC_GO_LOG_SEVERITY_LEVEL")
125 switch logLevel {
126 case "", "ERROR", "error": // If env is unset, set level to ERROR.
127 errorW = os.Stderr
128 case "WARNING", "warning":
129 warningW = os.Stderr
130 case "INFO", "info":
131 infoW = os.Stderr
132 }
133
134 var v int
135 vLevel := os.Getenv("GRPC_GO_LOG_VERBOSITY_LEVEL")
136 if vl, err := strconv.Atoi(vLevel); err == nil {
137 v = vl
138 }
139 return NewLoggerV2WithVerbosity(infoW, warningW, errorW, v)
140}
141
142func (g *loggerT) Info(args ...interface{}) {
143 g.m[infoLog].Print(args...)
144}
145
146func (g *loggerT) Infoln(args ...interface{}) {
147 g.m[infoLog].Println(args...)
148}
149
150func (g *loggerT) Infof(format string, args ...interface{}) {
151 g.m[infoLog].Printf(format, args...)
152}
153
154func (g *loggerT) Warning(args ...interface{}) {
155 g.m[warningLog].Print(args...)
156}
157
158func (g *loggerT) Warningln(args ...interface{}) {
159 g.m[warningLog].Println(args...)
160}
161
162func (g *loggerT) Warningf(format string, args ...interface{}) {
163 g.m[warningLog].Printf(format, args...)
164}
165
166func (g *loggerT) Error(args ...interface{}) {
167 g.m[errorLog].Print(args...)
168}
169
170func (g *loggerT) Errorln(args ...interface{}) {
171 g.m[errorLog].Println(args...)
172}
173
174func (g *loggerT) Errorf(format string, args ...interface{}) {
175 g.m[errorLog].Printf(format, args...)
176}
177
178func (g *loggerT) Fatal(args ...interface{}) {
179 g.m[fatalLog].Fatal(args...)
180 // No need to call os.Exit() again because log.Logger.Fatal() calls os.Exit().
181}
182
183func (g *loggerT) Fatalln(args ...interface{}) {
184 g.m[fatalLog].Fatalln(args...)
185 // No need to call os.Exit() again because log.Logger.Fatal() calls os.Exit().
186}
187
188func (g *loggerT) Fatalf(format string, args ...interface{}) {
189 g.m[fatalLog].Fatalf(format, args...)
190 // No need to call os.Exit() again because log.Logger.Fatal() calls os.Exit().
191}
192
193func (g *loggerT) V(l int) bool {
194 return l <= g.v
195}