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

*Logger type uses global backend in IsEnabledFor method #125

Open
triztian opened this issue May 1, 2018 · 0 comments
Open

*Logger type uses global backend in IsEnabledFor method #125

triztian opened this issue May 1, 2018 · 0 comments

Comments

@triztian
Copy link

triztian commented May 1, 2018

Whenever a new logger is created; it defaults to calling the global defaultBackend rather than it's own backend.

func (l *Logger) IsEnabledFor(level Level) bool {
	return defaultBackend.IsEnabledFor(level, l.Module)
}

This causes for the backend defined by the SetBackend method to be ignored unless set with the package method SetBackend; i.e:

package main

import (
    "os"
    "github.com/op/go-logging"
)

func main() {

    formatter := logging.MustStringFormatter("JUST A PREFIX: ${message}")
    backend := logging.NewLogBackend(os.Stdout, "", log.LstdFlags)
    lg := logging.MustGetLogger("example")
    backendFormatter := logging.NewBackendFormatter(backend, formatter)
    
    leveled := logging.AddModuleLevel(backendFormatter)
    leveled.SetLevel(logging.DEBUG, "")

    // The following will cause for the backend `leveled` to be ignored by `lg`
    lg.SetBackend(leveled)
    
    // This will set the backend globally
    logging.SetBackend(leveled)
}
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

1 participant