@@ -38,12 +38,15 @@ import (
3838 "regexp"
3939 "strconv"
4040 "strings"
41+ "sync"
4142)
4243
4344var PLACEHOLDER = regexp .MustCompile ("{(\\ d)}" )
4445
4546type Logger interface {
4647 Fprintln (w io.Writer , level string , format string , a ... interface {})
48+ UnformattedFprintln (w io.Writer , s string )
49+ UnformattedWrite (w io.Writer , data []byte )
4750 Println (level string , format string , a ... interface {})
4851 Name () string
4952}
@@ -52,6 +55,10 @@ type NoopLogger struct{}
5255
5356func (s NoopLogger ) Fprintln (w io.Writer , level string , format string , a ... interface {}) {}
5457
58+ func (s NoopLogger ) UnformattedFprintln (w io.Writer , str string ) {}
59+
60+ func (s NoopLogger ) UnformattedWrite (w io.Writer , data []byte ) {}
61+
5562func (s NoopLogger ) Println (level string , format string , a ... interface {}) {}
5663
5764func (s NoopLogger ) Name () string {
@@ -62,55 +69,98 @@ type HumanTagsLogger struct{}
6269
6370func (s HumanTagsLogger ) Fprintln (w io.Writer , level string , format string , a ... interface {}) {
6471 format = "[" + level + "] " + format
65- fmt . Fprintln (w , Format (format , a ... ))
72+ fprintln (w , Format (format , a ... ))
6673}
6774
6875func (s HumanTagsLogger ) Println (level string , format string , a ... interface {}) {
6976 s .Fprintln (os .Stdout , level , format , a ... )
7077}
7178
79+ func (s HumanTagsLogger ) UnformattedFprintln (w io.Writer , str string ) {
80+ fprintln (w , str )
81+ }
82+
83+ func (s HumanTagsLogger ) UnformattedWrite (w io.Writer , data []byte ) {
84+ write (w , data )
85+ }
86+
7287func (s HumanTagsLogger ) Name () string {
7388 return "humantags"
7489}
7590
7691type HumanLogger struct {}
7792
7893func (s HumanLogger ) Fprintln (w io.Writer , level string , format string , a ... interface {}) {
79- fmt . Fprintln (w , Format (format , a ... ))
94+ fprintln (w , Format (format , a ... ))
8095}
8196
8297func (s HumanLogger ) Println (level string , format string , a ... interface {}) {
8398 s .Fprintln (os .Stdout , level , format , a ... )
8499}
85100
101+ func (s HumanLogger ) UnformattedFprintln (w io.Writer , str string ) {
102+ fprintln (w , str )
103+ }
104+
105+ func (s HumanLogger ) UnformattedWrite (w io.Writer , data []byte ) {
106+ write (w , data )
107+ }
108+
86109func (s HumanLogger ) Name () string {
87110 return "human"
88111}
89112
90113type MachineLogger struct {}
91114
92- func (s MachineLogger ) printWithoutFormatting (w io.Writer , level string , format string , a []interface {}) {
115+ func (s MachineLogger ) Fprintln (w io.Writer , level string , format string , a ... interface {}) {
116+ printMachineFormattedLogLine (w , level , format , a )
117+ }
118+
119+ func (s MachineLogger ) Println (level string , format string , a ... interface {}) {
120+ printMachineFormattedLogLine (os .Stdout , level , format , a )
121+ }
122+
123+ func (s MachineLogger ) UnformattedFprintln (w io.Writer , str string ) {
124+ fprintln (w , str )
125+ }
126+
127+ func (s MachineLogger ) Name () string {
128+ return "machine"
129+ }
130+
131+ func (s MachineLogger ) UnformattedWrite (w io.Writer , data []byte ) {
132+ write (w , data )
133+ }
134+
135+ func printMachineFormattedLogLine (w io.Writer , level string , format string , a []interface {}) {
93136 a = append ([]interface {}(nil ), a ... )
94137 for idx , value := range a {
95138 typeof := reflect .Indirect (reflect .ValueOf (value )).Kind ()
96139 if typeof == reflect .String {
97140 a [idx ] = url .QueryEscape (value .(string ))
98141 }
99142 }
100- fmt .Fprintf (w , "===%s ||| %s ||| %s" , level , format , a )
101- fmt .Fprintln (w )
143+ fprintf (w , "===%s ||| %s ||| %s\n " , level , format , a )
102144}
103145
104- func (s MachineLogger ) Fprintln (w io.Writer , level string , format string , a ... interface {}) {
105- s .printWithoutFormatting (w , level , format , a )
146+ var lock sync.Mutex
147+
148+ func fprintln (w io.Writer , s string ) {
149+ lock .Lock ()
150+ defer lock .Unlock ()
151+ fmt .Fprintln (w , s )
106152}
107153
108- func (s MachineLogger ) Println (level string , format string , a ... interface {}) {
109- s .printWithoutFormatting (os .Stdout , level , format , a )
154+ func write (w io.Writer , data []byte ) {
155+ lock .Lock ()
156+ defer lock .Unlock ()
157+ w .Write (data )
110158}
111159
112- func (s MachineLogger ) Name () string {
113- return "machine"
160+ func fprintf (w io.Writer , format string , a ... interface {}) {
161+ lock .Lock ()
162+ defer lock .Unlock ()
163+ fmt .Fprintf (w , format , a ... )
114164}
115165
116166func FromJavaToGoSyntax (s string ) string {
0 commit comments