-
Notifications
You must be signed in to change notification settings - Fork 258
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
Allow constructing LevelFilter via incrementation #624
Comments
You can use I'm not sure this a common enough case that we need the crate, though. |
Are you sure? All versions of Rust which I tried this on say that the cast from Footnotes
|
This works: https://play.rust-lang.org/?version=stable&mode=debug&edition=2021&gist=1f583a914a1b153a80213f3cd78c8676 and it's safe only because of |
Agreed, but it would still be nice not having to resort to |
Not really, the compiler can't ensure you do |
Yes, I know. I meant that with an API like |
Which brings us back to
|
I agree that some kind of increment/decrement on log levels and/or filters would be useful. It would also circumvent the stated reasons the other issues were rejected (#318, #460). Namely, it doesn't increase exposure of the underlying integer representation to users. It still does, however, expose the exact sequence of elements, e.g. adding a new level between two existing levels might break someone's code. I don't know if that is an issue. |
The sequence is already exposed via the |
When implementing a command line application where logging is somewhat important (e.g. a longer-running service), I sometimes like to make the verbosity configurable via multiple sources such as configuration files, environment variables and command line options.
However, for the latter I usually want a somewhat different behavior. Rather than the number of
-v
(or--verbose
) flags setting the verbosity directly, I want each-v
to increase the level from whatever the baseline is, which may come from a config file or some default level.Currently, this requires some awkward code in applications. If we had the possibility to create a
LevelFilter
from an integer, this would be trivial. This was proposed in the past but clearly rejected (#318, #460). However, I didn't yet find anyone proposing the possibility of creating a level by incrementing someLevelFilter
.That could be done by either:
fn increment(self)
/fn (self)
toLevelFilter
,fn iter_from(self)
toLevelFilter
(whcih would be identical to the existingiter(self)
and save users at least some awkward filtering),std::ops::Add<usize>
and/orstd::ops::AddAssign<usize>
forLevelFilter
orstd::iter::Step
forLevelFilter
.The latter clearly needed to be feature gated (which would be awkward) and/or increase the MSRV, but would allow using
LevelFilter
withstd::ops::Range
s as anIterator
in the future. And of course, those options are not mutually exclusive. Thestd::iter::Step
impl can follow at some later point if/when it gets stabilized.The text was updated successfully, but these errors were encountered: