-
Notifications
You must be signed in to change notification settings - Fork 0
/
grpclog.go
127 lines (106 loc) · 4.25 KB
/
grpclog.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
/*
Copyright 2018 Gravitational, Inc.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package auth
import (
"fmt"
"github.com/sirupsen/logrus"
)
// if we ever would like to turn on logging for GRPC, we could do:
//
// import "google.golang.org/grpc/grpclog"
//
// func init() {
// grpclog.SetLoggerV2(&GLogger{
// Entry: logrus.WithFields(
// logrus.Fields{
// trace.Component: teleport.Component(teleport.ComponentAuth, teleport.ComponentGRPC),
// }),
// })
//
// However for now, it's simply too verbose to turn on at all times
// GLogger implements GRPC logger interface LoggerV2
type GLogger struct {
Entry *logrus.Entry
// Verbosity is verbosity as it's understood by GRPC
Verbosity int
}
// Info logs to INFO log. Arguments are handled in the manner of fmt.Print.
func (g *GLogger) Info(args ...interface{}) {
// GRPC is very verbose, so this is intentionally
// pushes info level statements as Teleport's debug level ones
g.Entry.Debug(args...)
}
// Infoln logs to INFO log. Arguments are handled in the manner of fmt.Println.
func (g *GLogger) Infoln(args ...interface{}) {
// GRPC is very verbose, so this is intentionally
// pushes info level statements as Teleport's debug level ones
g.Entry.Debug(fmt.Sprintln(args...))
}
// Infof logs to INFO log. Arguments are handled in the manner of fmt.Printf.
func (g *GLogger) Infof(format string, args ...interface{}) {
// GRPC is very verbose, so this is intentionally
// pushes info level statements as Teleport's debug level ones
g.Entry.Debugf(format, args...)
}
// Warning logs to WARNING log. Arguments are handled in the manner of fmt.Print.
func (g *GLogger) Warning(args ...interface{}) {
g.Entry.Warning(args...)
}
// Warningln logs to WARNING log. Arguments are handled in the manner of fmt.Println.
func (g *GLogger) Warningln(args ...interface{}) {
g.Entry.Warning(fmt.Sprintln(args...))
}
// Warningf logs to WARNING log. Arguments are handled in the manner of fmt.Printf.
func (g *GLogger) Warningf(format string, args ...interface{}) {
g.Entry.Warningf(format, args...)
}
// Error logs to ERROR log. Arguments are handled in the manner of fmt.Print.
func (g *GLogger) Error(args ...interface{}) {
g.Entry.Error(args...)
}
// Errorln logs to ERROR log. Arguments are handled in the manner of fmt.Println.
func (g *GLogger) Errorln(args ...interface{}) {
g.Entry.Error(fmt.Sprintln(args...))
}
// Errorf logs to ERROR log. Arguments are handled in the manner of fmt.Printf.
func (g *GLogger) Errorf(format string, args ...interface{}) {
g.Entry.Errorf(format, args...)
}
// Fatal logs to ERROR log. Arguments are handled in the manner of fmt.Print.
// gRPC ensures that all Fatal logs will exit with os.Exit(1).
// Implementations may also call os.Exit() with a non-zero exit code.
func (g *GLogger) Fatal(args ...interface{}) {
// Teleport can be used as a library, prevent GRPC
// from crashing the process
g.Entry.Error(args...)
}
// Fatalln logs to ERROR log. Arguments are handled in the manner of fmt.Println.
// gRPC ensures that all Fatal logs will exit with os.Exit(1).
// Implementations may also call os.Exit() with a non-zero exit code.
func (g *GLogger) Fatalln(args ...interface{}) {
// Teleport can be used as a library, prevent GRPC
// from crashing the process
g.Entry.Error(fmt.Sprintln(args...))
}
// Fatalf logs to ERROR log. Arguments are handled in the manner of fmt.Printf.
// gRPC ensures that all Fatal logs will exit with os.Exit(1).
// Implementations may also call os.Exit() with a non-zero exit code.
func (g *GLogger) Fatalf(format string, args ...interface{}) {
// Teleport can be used as a library, prevent GRPC
// from crashing the process
g.Entry.Errorf(format, args...)
}
// V reports whether verbosity level l is at least the requested verbose level.
func (g *GLogger) V(l int) bool {
return l <= g.Verbosity
}