Skip to content

Allow constructing LevelFilter via incrementation #624

Open
@neithernut

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) to LevelFilter,
  • a new fn iter_from(self) to LevelFilter (whcih would be identical to the existing iter(self) and save users at least some awkward filtering),
  • implementing std::ops::Add<usize> and/or std::ops::AddAssign<usize> for LevelFilter or
  • implementing the currently unstable std::iter::Step for LevelFilter.

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::Ranges 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.

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions