-
Notifications
You must be signed in to change notification settings - Fork 272
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
global SetLevel #26
Comments
That sounds like a great feature. I like the idea of thinking of this as the argument beeing a prefix, eg. "". The level logic would not set all loggers beneath it to a level but the |
@op sgtm. In that case, I suggest prefixing everything with Extending this analogy, i could totally see this making sense: log1 := logging.MustGetLogger("/")
log2 := logging.MustGetLogger("/foo")
log3 := logging.MustGetLogger("/foo/bar")
logging.SetLevel(logging.ERROR, "/foo") // log2 and log2 are now at logging.ERROR Or: log1 := logging.RootLogger() // has prefix of "/"
log2 := logging.NewLogger(log1, "foo") // has prefix /foo
log3 := logging.NewLogger(log2, "bar") // has prefix /foo/bar
logging.SetLevel(logging.ERROR, "/foo") // log2 and log2 are now at logging.ERROR Logger TreeNote that up there I'm constructing loggers explicitly, whereas you prefer static loggers ( I think go-logging could work phenomenally well with a logger-tree model similar to how google's |
@jbenet That's worth a thought. Why do you want to have relative paths for loggers though? I believe that might lead to code that is harder to reason about. Very flexible, I agree. I've been thinking of going the opposite route. Somehow, make it possible to just say Keep the ideas coming. :) |
On the contrary. Static initialziation is very hard to reason about / deal with when changing the package structure or instantiation of things. I'd follow the
seems too magic to me. sometimes i don't care about logging per package, but --say-- per incoming request. (useful to change logging level on specific requests across packages) |
One more reason. being able to do this (on a per-request, or whatever, basis): log := logger.WithPrefix("[Peer: %s] ", local.peer.ID())
log.Debug("trying to do something with %s and %s, with %s", thisThing, thatThing, anotherPeer.ID())
// [Peer: abcbacbacbbacbabc] trying to do something with aaaaa and bbbbb, with dfdffdfdfdffdfdfdfd
log.Error("something bad happened: %s", err)
// [Peer: abcbacbacbbacbabc] something bad happened: all the things broke. Instead of, everywhere: log.Debug("[Peer: %s] trying to do something with %s and %s, with %s", local.peer.ID(), thisThing, thatThing, anotherPeer.ID())
// [Peer: abcbacbacbbacbabc] trying to do something with aaaaa and bbbbb, with dfdffdfdfdffdfdfdfd
log.Error("[Peer: %s] something bad happened: %s", local.peer.ID(), err)
// [Peer: abcbacbacbbacbabc] something bad happened: all the things broke. |
Instead of "WithPrefix", I would check the design of structlog and go that way: log := log.Bind("Peer", local.peer.ID())
log = log.Bind("Other", foobar)
log.Debug("doing something") so basically store a |
We've multiple loggers, but would be nice to set the level of all of them in one place (e.g. normally all are at Error, but can bump one down specifically to debug that portion.
The text was updated successfully, but these errors were encountered: