File tree Expand file tree Collapse file tree 1 file changed +6
-5
lines changed Expand file tree Collapse file tree 1 file changed +6
-5
lines changed Original file line number Diff line number Diff line change @@ -153,8 +153,6 @@ var sinks struct {
153153}
154154
155155func init () {
156- sinks .stderr .w = os .Stderr
157-
158156 // Register stderr first: that way if we crash during file-writing at least
159157 // the log will have gone somewhere.
160158 logsink .TextSinks = append (logsink .TextSinks , & sinks .stderr , & sinks .file )
@@ -167,7 +165,7 @@ func init() {
167165// if they meet certain conditions.
168166type stderrSink struct {
169167 mu sync.Mutex
170- w io.Writer
168+ w io.Writer // if nil Emit uses os.Stderr directly
171169}
172170
173171// Enabled implements logsink.Text.Enabled. It returns true if any of the
@@ -182,8 +180,11 @@ func (s *stderrSink) Enabled(m *logsink.Meta) bool {
182180func (s * stderrSink ) Emit (m * logsink.Meta , data []byte ) (n int , err error ) {
183181 s .mu .Lock ()
184182 defer s .mu .Unlock ()
185-
186- dn , err := s .w .Write (data )
183+ w := s .w
184+ if w == nil {
185+ w = os .Stderr
186+ }
187+ dn , err := w .Write (data )
187188 n += dn
188189 return n , err
189190}
You can’t perform that action at this time.
0 commit comments