Description
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 some LevelFilter
.
That could be done by either:
- adding a new
fn increment(self)
/fn (self)
toLevelFilter
, - a new
fn iter_from(self)
toLevelFilter
(whcih would be identical to the existingiter(self)
and save users at least some awkward filtering), - implementing
std::ops::Add<usize>
and/orstd::ops::AddAssign<usize>
forLevelFilter
or - implementing the currently unstable
std::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
with std::ops::Range
s as an Iterator
in the future. And of course, those options are not mutually exclusive. The std::iter::Step
impl can follow at some later point if/when it gets stabilized.