lib/logger: Clean up LOGGER_DISCARD handing to unbreak tests

When using newLogger() with an io.Writer, that writer should in fact be
used...
This commit is contained in:
Jakob Borg 2019-01-13 10:22:01 +01:00
parent d4f0544d9e
commit 93ae9a1c2e

View File

@ -70,21 +70,20 @@ type logger struct {
var DefaultLogger = New()
func New() Logger {
if os.Getenv("LOGGER_DISCARD") != "" {
// Hack to completely disable logging, for example when running
// benchmarks.
return newLogger(ioutil.Discard)
}
return newLogger(controlStripper{os.Stdout})
}
func newLogger(w io.Writer) Logger {
res := &logger{
return &logger{
logger: log.New(w, "", DefaultFlags),
facilities: make(map[string]string),
debug: make(map[string]struct{}),
}
if os.Getenv("LOGGER_DISCARD") != "" {
// Hack to completely disable logging, for example when running benchmarks.
res.logger = log.New(ioutil.Discard, "", 0)
return res
}
res.logger = log.New(w, "", DefaultFlags)
return res
}
// AddHandler registers a new MessageHandler to receive messages with the