@@ -15,7 +15,7 @@ type logger struct {
15
15
sync.RWMutex
16
16
fileHandle * os.File
17
17
messages chan * message
18
- flushCh chan chan bool
18
+ flushCh chan struct {}
19
19
minLevel LogLevel
20
20
}
21
21
@@ -26,7 +26,7 @@ func init() {
26
26
l = & logger {}
27
27
l .fileHandle = os .Stderr
28
28
l .messages = make (chan * message , 1024 )
29
- l .flushCh = make (chan chan bool )
29
+ l .flushCh = make (chan struct {} )
30
30
31
31
go handleMessages ()
32
32
}
@@ -56,7 +56,9 @@ func SetMinimumLevel(level string) error {
56
56
return nil
57
57
}
58
58
59
- // SetLogFile sets the file to which messages will be logged to. Default is STDOUT.
59
+ // SetLogFile sets the file to which messages will be logged to. Can take
60
+ // "stdout" or "stderr" to log to os.Stdout and os.Stderr, respectively. If
61
+ // unset defaults to os.Stderr
60
62
func SetLogFile (path string ) error {
61
63
l .RWMutex .Lock ()
62
64
defer l .RWMutex .Unlock ()
@@ -69,6 +71,11 @@ func SetLogFile(path string) error {
69
71
return nil
70
72
}
71
73
fh = os .Stderr
74
+ } else if path == "stdout" {
75
+ if l .fileHandle == os .Stdout {
76
+ return nil
77
+ }
78
+ fh = os .Stdout
72
79
} else {
73
80
flags := os .O_APPEND | os .O_CREATE | os .O_WRONLY
74
81
fh , err = os .OpenFile (path , flags , 0644 )
@@ -87,9 +94,7 @@ func SetLogFile(path string) error {
87
94
88
95
// Flushes the log of at least 100 milliseconds worth of entries
89
96
func Flush () {
90
- retCh := make (chan bool )
91
- l .flushCh <- retCh
92
- <- retCh
97
+ l .flushCh <- struct {}{}
93
98
}
94
99
95
100
// logString generates the string which will be written to the logfile
@@ -146,8 +151,7 @@ func handleMessages() {
146
151
147
152
case <- time .After (100 * time .Millisecond ):
148
153
select {
149
- case flushret := <- l .flushCh :
150
- flushret <- true
154
+ case <- l .flushCh :
151
155
default : // Oh well
152
156
}
153
157
0 commit comments