Expand description
Logging configuration for clap applications.
This library provides a common set of flags for controlling logging in a CLI application, and
a default implementation for configuring logging based on those flags using non-blocking
tracing-subscriber when the tracing feature is enabled
(which is the default).
It also supports configuring logging before parsing arguments, to allow logging to be set up
using environment variables such as RUST_LOG or DEBUG_INVOCATION, respects the NO_COLOR
(https://no-color.org) and CLICOLOR_FORCE (https://bixense.com/clicolors/) environment
variables (and more), and adjusts defaults when it detects systemd.
§Example
use lloggs::{LoggingArgs, PreArgs};
use clap::Parser;
#[derive(Debug, Parser)]
struct Args {
#[command(flatten)]
logging: LoggingArgs,
// Your other arguments here
}
fn main() -> Result<(), Box<dyn std::error::Error + Send + Sync>> {
let mut _guard = PreArgs::parse().setup()?;
let args = Args::parse();
if _guard.is_none() {
_guard = Some(args.logging.setup(|v| match v {
0 => "info",
1 => "debug",
_ => "trace",
})?);
}
// Your application logic here
Ok(())
}§Features
§tracing (default)
Include functionality to instantiate a tracing_subscriber based on the logging options.
§miette-7
Return [miette::Report]s instead of Boxed errors.
Structs§
- Logging
Args - Clap flags that control logging.
- PreArgs
- Logging configuration obtained before parsing arguments.
- Worker
Guard - A guard that flushes spans/events associated to a
NonBlockingon a drop
Enums§
- Colour
Mode - Colour mode for terminal output.