quicli
quicli copied to clipboard
Set log verbosity of libraries
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 😄
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| {
// ...
}
}
Actually, it seems like the .filter(None, Warn) sets everything to filter at warn. The example I added to #45 behaves weirdly.
How about this:
- By default, only log errors.
-vlogs warnings from us and dependencies-vvand above only increase our log level- mention
env RUST_LOG=dep_name=infoand the likes in the docs (I'd be totally fine with a guide on how to use logging!)
@killercup I like that plan. I wouldn't want to go any further than that to keep quicli simple.
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.
Actually, I think my original issue was #60
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.