@@ -26,15 +26,11 @@ import (
2626 "sync"
2727)
2828
29- var PLACEHOLDER = regexp .MustCompile (" {(\\ d)}" )
29+ var PLACEHOLDER = regexp .MustCompile (` {(\d)}` )
3030
3131type Logger interface {
3232 Fprintln (w io.Writer , level string , format string , a ... interface {})
33- UnformattedFprintln (w io.Writer , s string )
34- UnformattedWrite (w io.Writer , data []byte )
3533 Println (level string , format string , a ... interface {})
36- Name () string
37- Flush () string
3834}
3935
4036type LoggerToCustomStreams struct {
@@ -43,7 +39,7 @@ type LoggerToCustomStreams struct {
4339 mux sync.Mutex
4440}
4541
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 {}) {
4743 s .mux .Lock ()
4844 defer s .mux .Unlock ()
4945 target := s .Stdout
@@ -53,165 +49,47 @@ func (s LoggerToCustomStreams) Fprintln(w io.Writer, level string, format string
5349 fmt .Fprintln (target , Format (format , a ... ))
5450}
5551
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 {}) {
7753 s .Fprintln (nil , level , format , a ... )
7854}
7955
80- func (s LoggerToCustomStreams ) Flush () string {
81- return ""
82- }
83-
84- func (s LoggerToCustomStreams ) Name () string {
85- return "LoggerToCustomStreams"
86- }
87-
8856type NoopLogger struct {}
8957
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 {}) {}
9359
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 {}) {}
13561
13662type HumanTagsLogger struct {}
13763
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 {}) {
13965 format = "[" + level + "] " + format
14066 fprintln (w , Format (format , a ... ))
14167}
14268
143- func (s HumanTagsLogger ) Println (level string , format string , a ... interface {}) {
69+ func (s * HumanTagsLogger ) Println (level string , format string , a ... interface {}) {
14470 s .Fprintln (os .Stdout , level , format , a ... )
14571}
14672
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-
16373type HumanLogger struct {}
16474
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 {}) {
16676 fprintln (w , Format (format , a ... ))
16777}
16878
169- func (s HumanLogger ) Println (level string , format string , a ... interface {}) {
79+ func (s * HumanLogger ) Println (level string , format string , a ... interface {}) {
17080 s .Fprintln (os .Stdout , level , format , a ... )
17181}
17282
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-
18983type MachineLogger struct {}
19084
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 {}) {
19286 printMachineFormattedLogLine (w , level , format , a )
19387}
19488
195- func (s MachineLogger ) Println (level string , format string , a ... interface {}) {
89+ func (s * MachineLogger ) Println (level string , format string , a ... interface {}) {
19690 printMachineFormattedLogLine (os .Stdout , level , format , a )
19791}
19892
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-
21593func printMachineFormattedLogLine (w io.Writer , level string , format string , a []interface {}) {
21694 a = append ([]interface {}(nil ), a ... )
21795 for idx , value := range a {
@@ -232,12 +110,6 @@ func fprintln(w io.Writer, s string) {
232110 fmt .Fprintln (w , s )
233111}
234112
235- func write (w io.Writer , data []byte ) {
236- lock .Lock ()
237- defer lock .Unlock ()
238- w .Write (data )
239- }
240-
241113func fprintf (w io.Writer , format string , a ... interface {}) {
242114 lock .Lock ()
243115 defer lock .Unlock ()
0 commit comments