Function jacklog::from_level

source ·
pub fn from_level(
    level: u8,
    crates: Option<&[&str]>
) -> Result<(), SetGlobalDefaultError>
Expand description

Set the log level using 0-indexed integers, starting from 0=off. Especially useful if writing a CLI and accepting verbosity settings via number of flags (-v, -vv, -vvv, etc.). Will be overridden via the usual RUST_LOG env var, if it’s present.

In what is probably the most common use case for this method, where a repeating flag is used to increase verbosity, do the following math for the behavior you want:

Default of warn, with increasing verbosity when number of -v arguments is one or more:

2 + (number of -v flags)

Default of no logging, with increasing verbosity when number of -v arguments is one or more:

0 + (number of -v flags)

Default of info, with increasing verbosity when number of -v arguments is one or more:

3 + (number of -v flags)

You probably get the idea.

Errors

Will return an error if there’s an issue setting the global subscriber.