Skip to content
This repository has been archived by the owner on Sep 13, 2023. It is now read-only.

Set log verbosity of libraries #46

Open
CAD97 opened this issue Feb 9, 2018 · 7 comments
Open

Set log verbosity of libraries #46

CAD97 opened this issue Feb 9, 2018 · 7 comments

Comments

@CAD97
Copy link
Contributor

CAD97 commented Feb 9, 2018

When setting verbosity via StructOpt, logging from the binary is set to the listed verbosity, but all dependencies are always Warn only.

quicli/src/main_macro.rs

Lines 46 to 47 in 3a2f20e

.filter(Some(env!("CARGO_PKG_NAME")), log_level)
.filter(None, $crate::prelude::LogLevel::Warn.to_level_filter())

In my case I have a binary which is a different crate from the library it's a front to, because I'm already in a large workspace and I want to separate out the binary's dependencies from the library's, which is used elsewhere as well.

I would like to be able to allow the verbosity setting to effect certain dependencies as well. Side note, when at verbosity=0, the dependencies are louder than the first-party code 😄

@CAD97
Copy link
Contributor Author

CAD97 commented Feb 9, 2018

Full on over-engineering mode: allow manual mapping from verbosity count to filters.

main! {
    logging {
        0 => Error;
        1 => Warn;
        2 => (me, Info), Warn;
        3 => (me, Info), ("my_lib", Info), Warn;
        4 => Info;
        5 => Debug;
        _ => Trace;
    }
    |args: Cli, log_level: verbosity| {
        // ...
    }
}

@CAD97
Copy link
Contributor Author

CAD97 commented Feb 9, 2018

Actually, it seems like the .filter(None, Warn) sets everything to filter at warn. The example I added to #45 behaves weirdly.

@killercup
Copy link
Owner

How about this:

  • By default, only log errors.
  • -v logs warnings from us and dependencies
  • -vv and above only increase our log level
  • mention env RUST_LOG=dep_name=info and the likes in the docs (I'd be totally fine with a guide on how to use logging!)

@vitiral
Copy link
Contributor

vitiral commented Feb 10, 2018

@killercup I like that plan. I wouldn't want to go any further than that to keep quicli simple.

@nbigaouette
Copy link

My CLI is split in a lib and a bin crate, inside a workspace. The bin crate is only used to parse options, read input file, etc. The main logic is moved to the lib so it can be re-used elsewhere.

As such, I don't really care about the logging level of the bin crate, as it's mostly empty. I would like to "forward" the verbosity to my lib.

And optionally, it would make sense I guess to be able to control all others too using RUST_LOG=crate=... if required.

@CAD97
Copy link
Contributor Author

CAD97 commented Feb 17, 2018

Actually, I think my original issue was #60

@spease
Copy link

spease commented Apr 11, 2018

It'd be nice if you could max out the log level if you really wanted to. Say things start with @killercup 's proposal, but then if you max out "our log level" it starts increasing all library verbosity as well.

Otherwise it seems like the behavior is to override RUST_LOG and there's no way to see debug messages from libraries.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

5 participants