go-logging
go-logging copied to clipboard
init() { Reset() } clobbers any previously-set custom logging levels
init() { Reset() }
at the bottom of logger.go clobbers any previously-set custom logging levels.
// Reset restores the internal state of the logging library.
func Reset() {
// TODO make a global Init() method to be less magic? or make it such that
// if there's no backends at all configured, we could use some tricks to
// automatically setup backends based if we have a TTY or not.
sequenceNo = 0
b := SetBackend(NewLogBackend(os.Stderr, "", log.LstdFlags))
b.SetLevel(DEBUG, "")
SetFormatter(DefaultFormatter)
timeNow = time.Now
}
+1 for making it be less magic, would strongly prefer to explicitly invoke .Init()
or .Reset()
during initial logger setup/configuration.
This just cost me at 2 hours of time to track down why the custom log levels were not working, and I'd love a more elegant solution than the ugly hack of adding the following fragment around all the logging setup and configuration code:
// Wait until after logging.init() has had a chance to run.
go func() {
time.Sleep(time.Second)
...
}()```
This sounds definitely fixable. Just don't have the time to fix it. Sounds like sync.Once
would fix this.