quicli icon indicating copy to clipboard operation
quicli copied to clipboard

Set log verbosity of libraries

Open CAD97 opened this issue 7 years ago • 7 comments

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

https://github.com/killercup/quicli/blob/3a2f20e608281e9baa7e4e0c21f1484e03136e69/src/main_macro.rs#L46-L47

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 avatar Feb 09 '18 08:02 CAD97

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 avatar Feb 09 '18 08:02 CAD97

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

CAD97 avatar Feb 09 '18 23:02 CAD97

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

killercup avatar Feb 10 '18 16:02 killercup

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

vitiral avatar Feb 10 '18 17:02 vitiral

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.

nbigaouette avatar Feb 15 '18 02:02 nbigaouette

Actually, I think my original issue was #60

CAD97 avatar Feb 17 '18 00:02 CAD97

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.

spease avatar Apr 11 '18 10:04 spease