quicli icon indicating copy to clipboard operation
quicli copied to clipboard

Add set_log_verbosity function

Open vitiral opened this issue 7 years ago • 4 comments

#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)])
  • lowest is the lowest log level, i.e. set to 1 to enable all warnings.
  • levels is a tuple containing the custom levels for specific crates.

This gives complete flexibility but is also very simple.

Discuss!

vitiral avatar Feb 13 '18 16:02 vitiral

Could the levels be enums and not integers? There was also discussion about using RUST_LOG in #46. How would that fit in?

nbigaouette avatar Feb 15 '18 02:02 nbigaouette

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<()>

CAD97 avatar Feb 16 '18 06:02 CAD97

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)

killercup avatar Feb 16 '18 16:02 killercup

I'm thinking if no -v flags are given then we use the environment, otherwise we do the current behavior.

vitiral avatar Feb 16 '18 16:02 vitiral