Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

init() { Reset() } clobbers any previously-set custom logging levels #59

Open
jaytaylor opened this issue Jun 17, 2015 · 1 comment
Open

Comments

@jaytaylor
Copy link

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)
    ...
}()```
@op
Copy link
Owner

op commented Nov 24, 2015

This sounds definitely fixable. Just don't have the time to fix it. Sounds like sync.Once would fix this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants