@@ -26,15 +26,11 @@ import (
26
26
"sync"
27
27
)
28
28
29
- var PLACEHOLDER = regexp .MustCompile (" {(\\ d)}" )
29
+ var PLACEHOLDER = regexp .MustCompile (` {(\d)}` )
30
30
31
31
type Logger interface {
32
32
Fprintln (w io.Writer , level string , format string , a ... interface {})
33
- UnformattedFprintln (w io.Writer , s string )
34
- UnformattedWrite (w io.Writer , data []byte )
35
33
Println (level string , format string , a ... interface {})
36
- Name () string
37
- Flush () string
38
34
}
39
35
40
36
type LoggerToCustomStreams struct {
@@ -43,7 +39,7 @@ type LoggerToCustomStreams struct {
43
39
mux sync.Mutex
44
40
}
45
41
46
- func (s LoggerToCustomStreams ) Fprintln (w io.Writer , level string , format string , a ... interface {}) {
42
+ func (s * LoggerToCustomStreams ) Fprintln (w io.Writer , level string , format string , a ... interface {}) {
47
43
s .mux .Lock ()
48
44
defer s .mux .Unlock ()
49
45
target := s .Stdout
@@ -53,165 +49,47 @@ func (s LoggerToCustomStreams) Fprintln(w io.Writer, level string, format string
53
49
fmt .Fprintln (target , Format (format , a ... ))
54
50
}
55
51
56
- func (s LoggerToCustomStreams ) UnformattedFprintln (w io.Writer , str string ) {
57
- s .mux .Lock ()
58
- defer s .mux .Unlock ()
59
- target := s .Stdout
60
- if w == os .Stderr {
61
- target = s .Stderr
62
- }
63
- fmt .Fprintln (target , str )
64
- }
65
-
66
- func (s LoggerToCustomStreams ) UnformattedWrite (w io.Writer , data []byte ) {
67
- s .mux .Lock ()
68
- defer s .mux .Unlock ()
69
- target := s .Stdout
70
- if w == os .Stderr {
71
- target = s .Stderr
72
- }
73
- target .Write (data )
74
- }
75
-
76
- func (s LoggerToCustomStreams ) Println (level string , format string , a ... interface {}) {
52
+ func (s * LoggerToCustomStreams ) Println (level string , format string , a ... interface {}) {
77
53
s .Fprintln (nil , level , format , a ... )
78
54
}
79
55
80
- func (s LoggerToCustomStreams ) Flush () string {
81
- return ""
82
- }
83
-
84
- func (s LoggerToCustomStreams ) Name () string {
85
- return "LoggerToCustomStreams"
86
- }
87
-
88
56
type NoopLogger struct {}
89
57
90
- func (s NoopLogger ) Fprintln (w io.Writer , level string , format string , a ... interface {}) {}
91
-
92
- func (s NoopLogger ) UnformattedFprintln (w io.Writer , str string ) {}
58
+ func (s * NoopLogger ) Fprintln (w io.Writer , level string , format string , a ... interface {}) {}
93
59
94
- func (s NoopLogger ) UnformattedWrite (w io.Writer , data []byte ) {}
95
-
96
- func (s NoopLogger ) Println (level string , format string , a ... interface {}) {}
97
-
98
- func (s NoopLogger ) Flush () string {
99
- return ""
100
- }
101
-
102
- func (s NoopLogger ) Name () string {
103
- return "noop"
104
- }
105
-
106
- type AccumulatorLogger struct {
107
- Buffer * []string
108
- }
109
-
110
- func (s AccumulatorLogger ) Fprintln (w io.Writer , level string , format string , a ... interface {}) {
111
- * s .Buffer = append (* s .Buffer , Format (format , a ... ))
112
- }
113
-
114
- func (s AccumulatorLogger ) UnformattedFprintln (w io.Writer , str string ) {
115
- * s .Buffer = append (* s .Buffer , str )
116
- }
117
-
118
- func (s AccumulatorLogger ) UnformattedWrite (w io.Writer , data []byte ) {
119
- * s .Buffer = append (* s .Buffer , string (data ))
120
- }
121
-
122
- func (s AccumulatorLogger ) Println (level string , format string , a ... interface {}) {
123
- s .Fprintln (nil , level , format , a ... )
124
- }
125
-
126
- func (s AccumulatorLogger ) Flush () string {
127
- str := strings .Join (* s .Buffer , "\n " )
128
- * s .Buffer = (* s .Buffer )[0 :0 ]
129
- return str
130
- }
131
-
132
- func (s AccumulatorLogger ) Name () string {
133
- return "accumulator"
134
- }
60
+ func (s * NoopLogger ) Println (level string , format string , a ... interface {}) {}
135
61
136
62
type HumanTagsLogger struct {}
137
63
138
- func (s HumanTagsLogger ) Fprintln (w io.Writer , level string , format string , a ... interface {}) {
64
+ func (s * HumanTagsLogger ) Fprintln (w io.Writer , level string , format string , a ... interface {}) {
139
65
format = "[" + level + "] " + format
140
66
fprintln (w , Format (format , a ... ))
141
67
}
142
68
143
- func (s HumanTagsLogger ) Println (level string , format string , a ... interface {}) {
69
+ func (s * HumanTagsLogger ) Println (level string , format string , a ... interface {}) {
144
70
s .Fprintln (os .Stdout , level , format , a ... )
145
71
}
146
72
147
- func (s HumanTagsLogger ) UnformattedFprintln (w io.Writer , str string ) {
148
- fprintln (w , str )
149
- }
150
-
151
- func (s HumanTagsLogger ) UnformattedWrite (w io.Writer , data []byte ) {
152
- write (w , data )
153
- }
154
-
155
- func (s HumanTagsLogger ) Flush () string {
156
- return ""
157
- }
158
-
159
- func (s HumanTagsLogger ) Name () string {
160
- return "humantags"
161
- }
162
-
163
73
type HumanLogger struct {}
164
74
165
- func (s HumanLogger ) Fprintln (w io.Writer , level string , format string , a ... interface {}) {
75
+ func (s * HumanLogger ) Fprintln (w io.Writer , level string , format string , a ... interface {}) {
166
76
fprintln (w , Format (format , a ... ))
167
77
}
168
78
169
- func (s HumanLogger ) Println (level string , format string , a ... interface {}) {
79
+ func (s * HumanLogger ) Println (level string , format string , a ... interface {}) {
170
80
s .Fprintln (os .Stdout , level , format , a ... )
171
81
}
172
82
173
- func (s HumanLogger ) UnformattedFprintln (w io.Writer , str string ) {
174
- fprintln (w , str )
175
- }
176
-
177
- func (s HumanLogger ) UnformattedWrite (w io.Writer , data []byte ) {
178
- write (w , data )
179
- }
180
-
181
- func (s HumanLogger ) Flush () string {
182
- return ""
183
- }
184
-
185
- func (s HumanLogger ) Name () string {
186
- return "human"
187
- }
188
-
189
83
type MachineLogger struct {}
190
84
191
- func (s MachineLogger ) Fprintln (w io.Writer , level string , format string , a ... interface {}) {
85
+ func (s * MachineLogger ) Fprintln (w io.Writer , level string , format string , a ... interface {}) {
192
86
printMachineFormattedLogLine (w , level , format , a )
193
87
}
194
88
195
- func (s MachineLogger ) Println (level string , format string , a ... interface {}) {
89
+ func (s * MachineLogger ) Println (level string , format string , a ... interface {}) {
196
90
printMachineFormattedLogLine (os .Stdout , level , format , a )
197
91
}
198
92
199
- func (s MachineLogger ) UnformattedFprintln (w io.Writer , str string ) {
200
- fprintln (w , str )
201
- }
202
-
203
- func (s MachineLogger ) Flush () string {
204
- return ""
205
- }
206
-
207
- func (s MachineLogger ) Name () string {
208
- return "machine"
209
- }
210
-
211
- func (s MachineLogger ) UnformattedWrite (w io.Writer , data []byte ) {
212
- write (w , data )
213
- }
214
-
215
93
func printMachineFormattedLogLine (w io.Writer , level string , format string , a []interface {}) {
216
94
a = append ([]interface {}(nil ), a ... )
217
95
for idx , value := range a {
@@ -232,12 +110,6 @@ func fprintln(w io.Writer, s string) {
232
110
fmt .Fprintln (w , s )
233
111
}
234
112
235
- func write (w io.Writer , data []byte ) {
236
- lock .Lock ()
237
- defer lock .Unlock ()
238
- w .Write (data )
239
- }
240
-
241
113
func fprintf (w io.Writer , format string , a ... interface {}) {
242
114
lock .Lock ()
243
115
defer lock .Unlock ()
0 commit comments