Skip to content
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

Need to depend on the log crate to manually compare LevelFilter #54

Closed
Zykino opened this issue Jan 22, 2023 · 5 comments · Fixed by #56
Closed

Need to depend on the log crate to manually compare LevelFilter #54

Zykino opened this issue Jan 22, 2023 · 5 comments · Fixed by #56

Comments

@Zykino
Copy link

Zykino commented Jan 22, 2023

To make the sample code I wrote in #53 work, we need to depend on the log crate.
Fixed sample code:

use log; // Need this and adding the dependency in Cargo.toml

fn foo() {
    if opt.verbose.log_level_filter() <= LevelFilter::Warn {
        eprintln!("Hide command's stdout");
    }

    if opt.verbose.log_level_filter() <= LevelFilter::Error {
        eprintln!("Hide command's stderr");
    }
}

I’m not sure if I want to use the log crate or tracing yet… Since this crate can support both logging frameworks, it feels strange to be forced to depends on the log crate to manually manage the log level.

I think the LevelFilter could be re-exported (and maybe Level too).

@matthiasbeyer
Copy link
Contributor

Hey, thanks for your report!

So if we'd re-export LevelFilter, you would still depend on log, just not directly but transitively!

What I would rather imagine is that we define our own LevelFilter and provide From<LevelFilter> for log::LevelFilter and From<LevelFilter> for tracing::level_filters::LevelFilter behind feature gates.

What do you think?

@Zykino
Copy link
Author

Zykino commented Jan 23, 2023

Sure, I proposed a "simple" re-export but having an internal representation sounds better. "Worst" cases scenario the raw verbosity value like proposed in #53. "Worst" in the sense that it take the familiar C approach instead of using a higher level data type.

@adriandelgado
Copy link

+1 to the feature gates idea

epage added a commit to epage/clap-verbosity-flag that referenced this issue Mar 31, 2023
@epage
Copy link
Member

epage commented Mar 31, 2023

log is already in the public API and is unlikely to change. I'm going to go ahead and re-export

@matthiasbeyer
Copy link
Contributor

matthiasbeyer commented Mar 31, 2023 via email

@epage epage closed this as completed in #56 Mar 31, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants