#clap #logging #cli

lloggs

Logging configuration for clap applications

7 stable releases

1.4.0 Feb 18, 2026
1.3.0 Dec 18, 2025
1.2.1 Sep 13, 2025
1.1.0 Apr 19, 2025
1.0.1 Feb 4, 2025

#365 in Debugging

38 downloads per month
Used in 3 crates

Apache-2.0 OR MIT

22KB
248 lines

lloggs

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 environment variable (https://no-color.org), 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(())
}

Dependencies

~1–6MB
~96K SLoC