In go-nsq
library (https://github.com/bitly/go-nsq/blob/master/writer_test.go#L38), I found the following code:
log.SetOutput(ioutil.Discard)
defer log.SetOutput(os.Stdout)
Why does the author defer logging to stdout after discard the log?
In go-nsq
library (https://github.com/bitly/go-nsq/blob/master/writer_test.go#L38), I found the following code:
log.SetOutput(ioutil.Discard)
defer log.SetOutput(os.Stdout)
Why does the author defer logging to stdout after discard the log?
Copyright © 2021 Jogjafile Inc.
The
log.SetOutput(ioutil.Discard)
statement changes the standard logger output destination. Thedefer log.SetOutput(os.Stdout)
statement attempts to reset the output destination back to its initial value when the function ends. However, it should have reset it back toos.Stderr
.src/pkg/log/log.go