lloggs

Crates.iolloggs
lib.rslloggs
version1.2.1
created_at2025-02-03 01:02:51.040563+00
updated_at2025-09-13 13:40:47.175645+00
descriptionLogging configuration for clap applications
homepage
repositoryhttps://github.com/passcod/lloggs
max_upload_size
id1540005
size48,970
Félix Saparelli (passcod)

documentation

https://docs.rs/lloggs

README

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(())
}
Commit count: 16

cargo fmt