@@ -5,16 +5,26 @@ import (
5
5
"github.com/sirupsen/logrus"
6
6
)
7
7
8
- // Logger handles the logging in the gateway library
9
- type Logger struct {
8
+ // Logger logs messages
9
+ type Logger interface {
10
+ Debug (args ... interface {})
11
+ Info (args ... interface {})
12
+ Warn (args ... interface {})
13
+
14
+ WithFields (fields LoggerFields ) Logger
15
+ QueryPlanStep (step * QueryPlanStep )
16
+ }
17
+
18
+ // DefaultLogger handles the logging in the gateway library
19
+ type DefaultLogger struct {
10
20
fields logrus.Fields
11
21
}
12
22
13
23
// LoggerFields is a wrapper over a map of key,value pairs to associate with the log
14
24
type LoggerFields map [string ]interface {}
15
25
16
26
// Debug should be used for any logging that would be useful for debugging
17
- func (l * Logger ) Debug (args ... interface {}) {
27
+ func (l * DefaultLogger ) Debug (args ... interface {}) {
18
28
entry := newLogEntry ()
19
29
// if there are fields
20
30
if l .fields != nil {
@@ -26,7 +36,7 @@ func (l *Logger) Debug(args ...interface{}) {
26
36
}
27
37
28
38
// Info should be used for any logging that doesn't necessarily need attention but is nice to see by default
29
- func (l * Logger ) Info (args ... interface {}) {
39
+ func (l * DefaultLogger ) Info (args ... interface {}) {
30
40
entry := newLogEntry ()
31
41
// if there are fields
32
42
if l .fields != nil {
@@ -38,7 +48,7 @@ func (l *Logger) Info(args ...interface{}) {
38
48
}
39
49
40
50
// Warn should be used for logging that needs attention
41
- func (l * Logger ) Warn (args ... interface {}) {
51
+ func (l * DefaultLogger ) Warn (args ... interface {}) {
42
52
entry := newLogEntry ()
43
53
// if there are fields
44
54
if l .fields != nil {
@@ -50,26 +60,26 @@ func (l *Logger) Warn(args ...interface{}) {
50
60
}
51
61
52
62
// WithFields adds the provided fields to the Log
53
- func (l * Logger ) WithFields (fields LoggerFields ) * Logger {
63
+ func (l * DefaultLogger ) WithFields (fields LoggerFields ) Logger {
54
64
// build up the logrus fields
55
65
logrusFields := logrus.Fields {}
56
66
for key , value := range fields {
57
67
logrusFields [key ] = value
58
68
}
59
- return & Logger {fields : logrusFields }
69
+ return & DefaultLogger {fields : logrusFields }
60
70
}
61
71
62
72
// QueryPlanStep formats and logs a query plan step for human consumption
63
- func (l * Logger ) QueryPlanStep (step * QueryPlanStep ) {
64
- log .WithFields (LoggerFields {
73
+ func (l * DefaultLogger ) QueryPlanStep (step * QueryPlanStep ) {
74
+ l .WithFields (LoggerFields {
65
75
"id" : step .ParentID ,
66
76
"insertion point" : step .InsertionPoint ,
67
77
}).Info (step .ParentType )
68
78
69
- log .Info (graphql .FormatSelectionSet (step .SelectionSet ))
79
+ l .Info (graphql .FormatSelectionSet (step .SelectionSet ))
70
80
}
71
81
72
- var log * Logger
82
+ var log Logger = & DefaultLogger {}
73
83
74
84
func newLogEntry () * logrus.Entry {
75
85
entry := logrus .New ()
@@ -86,7 +96,3 @@ func newLogEntry() *logrus.Entry {
86
96
87
97
return logrus .NewEntry (entry )
88
98
}
89
- func init () {
90
- log = & Logger {}
91
-
92
- }
0 commit comments