quicli
quicli copied to clipboard
Add set_log_verbosity function
#51 adds a hidden set_log_verbosity function which is currently an implementation detail of the main! macro. However, I would like to break it out into a general enough function that could be used outside of main!.
This comment proposed the following API
fn set_log_verbosity(lowest: u64, levels: &[(&str, u64)])
lowestis the lowest log level, i.e. set to1to enable all warnings.levelsis a tuple containing the custom levels for specific crates.
This gives complete flexibility but is also very simple.
Discuss!
Could the levels be enums and not integers? There was also discussion about using RUST_LOG in #46. How would that fit in?
I think LoggerBuilder::from_env should be called at the start, such that an environment variable can be used for overrides. I mean, that's the reason to use env_logger, isn't it? But that seems orthogonal.
If we're designing an easy wrapper around "the logging implementation", we shouldn't be afraid to use log's terminology to talk about it. Therefore I think the following signature feels best currently (subject to bikeshed of course):
fn set_up_logger(
default: ::log::LevelFilter,
overrides: &[(&str, ::log::LevelFilter)],
) -> Result<()>
I think LoggerBuilder::from_env should be called at the start
:+1:
If we're designing an easy wrapper around "the logging implementation"
FTR, originally, the function was about turning "number of -v flags given" into a LogLevel.
I'm still unsure of what kind of API to expose (cf. https://github.com/killercup/quicli/pull/51#discussion_r167404398)
I'm thinking if no -v flags are given then we use the environment, otherwise we do the current behavior.