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

Consider changing the default enabled log levels #147

Closed
alexcrichton opened this issue May 19, 2017 · 11 comments
Closed

Consider changing the default enabled log levels #147

alexcrichton opened this issue May 19, 2017 · 11 comments

Comments

@alexcrichton
Copy link
Member

Right now I believe all log levels are enabled by default in all builds. @sfackler provided some good rationale for this during the evaluation, @sfackler want to copy that down here as well?

In any case would be worth discussing before a 1.0 release!

@lucab
Copy link

lucab commented Jun 1, 2017

Bump for this for the missing offline comments. Also, has build-time stubbing of disabled levels (like slog does) been discussed? Is it in scope here?

@sfackler
Copy link
Member

sfackler commented Jun 1, 2017

Oops, sorry!

You can already statically disable levels actually: https://github.com/rust-lang-nursery/log/blob/master/Cargo.toml#L23-L35. The question here is over defaults.

I feel pretty strongly that we shouldn't disable any level of logging by default. The whole point of logging is that you have bunch of diagnostic information available to you when you need it. You normally don't need to look at debug or trace level logging, but when you do it's invaluable! For example, Hyper's trace-level logging helped track down a bug in its chunked request body parser in a running server.

If, for example, trace logging were disabled by default, you'd have several problems. If I ran into that Hyper problem above, I'd have to ship a new custom build of the server with trace logging enabled to actually be able to get the information I need. If the issue you're looking into is one of the annoying transient ones that no-one knows how to reproduce but pops up in production every once in a while, it's really important to be able to look very closely at whatever box it shows up on immediately! I could also override the default to enable trace logging by default, but then I potentially have other issues - if people become too used to trace logging being turned off, you may run into issues where those log events are extremely expensive or even broken! Rustc has some of those issues - the old log framework disabled debug logging in prod builds, and didn't evaluate log arguments if the log event wasn't enabled and it turned out that several would panic if actually evaluated.

In addition, there is a fast path for logging levels that are entirely disabled at runtime. If you don't have any trace-level logging enabled in your logger configuration, the cost of a trace! statement is a relaxed atomic load, comparison against a constant, and branch. If you're logging so much that that fast path ends up slowing things down significantly, I don't really see how that level of verbosity can possibly be useful.

@lucab
Copy link

lucab commented Jun 1, 2017

Thanks for the feedback! It looks like my knowledge around here is wrong/stale, so I'm paging @dpc for some informed comment.

@dpc
Copy link

dpc commented Jun 1, 2017

I understand @sfackler points, and I think they make sense. I also don't feel strongly about default logging level in slog. I gave the matter some consideration and picked the defaults.

As a library writer, it is convenient to have a logging level for your disposal, that you don't have to feel guilty about using, and comes handy when you are testing and debugging your library while you are working on it, change it etc.. It is not optimal if hyper is important enough to have trace information, but mysillylibrarymust be cautious or jump through custom macro hoops because it's somehow of lesser category or something like that. So that would be my main concern. I was hoping to get to think about it more, and maybe do some prototyping of something that could satisfy everyone, ideas include:

  • special set of logging macros that can be used when working on the library itself
  • statically compiled logging levels per-crate

There are some differences between slog and slog that change the dynamics a bit: slog supports lazily evaluated values, so the risk of panics during with logging enabled is inherent. That is kind of OK, because slog treats logging as first class citizen. You need to take care of API changes related to logging, logging logical structure and context etc.

Also, because in slog you do compose how the different pices of your software route their logging messages, it is possible to modify in-flight eg. lowering logging levels of your dependencies. Even if they do overuse trace, or debug, and you turned it on, they still wouldn't get logged and their overhead would be minimal.

So in slog, if there's something useful to know in production, no matter how minor it might be from global perspective you can make it an info. If something is only useful for debugging you make it debug, and so on. The users of your library can decide how much they care (or typically not care). And you can stuff your code with trace for your own (maintainer/developer of given library) use, without much worrying about affecting your users.

So I don't think log should neccesarily copy slog defaults.

@lucab
Copy link

lucab commented Jun 1, 2017

For reference, I ended up here today because of such discussions happening around TLS libraries and logging:

@brson
Copy link
Contributor

brson commented Jun 3, 2017

I think a concur that all log levels should be compiled in by default. Would be quite surprising for a naive user to deploy an app, go to turn on verbose logs and discover they don't exist.

@brson
Copy link
Contributor

brson commented Jul 6, 2017

Probably about time to decide one way or the other here.

@brson
Copy link
Contributor

brson commented Jul 15, 2017

cc @sfackler @alexcrichton

@alexcrichton
Copy link
Member Author

I'm personally on board with "compile everything in by default"

@KodrAus
Copy link
Contributor

KodrAus commented Oct 2, 2017

Compiling all by default sounds good to me too. Are we happy to close this or would you like to keep it open to solicit some more feedback?

@sfackler
Copy link
Member

sfackler commented Oct 2, 2017

I think we're good to go.

@sfackler sfackler closed this as completed Oct 2, 2017
EFanZh pushed a commit to EFanZh/log that referenced this issue Jul 23, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

6 participants