clap-logflag 0.2.1

This library can be used to add a `--log` flag to clap based command line applications that allows users to configure logging from the command line. It can log to stderr, files and syslog, powered by the fern logging backend.
Documentation
use clap::Parser;
use clap_logflag::{LogDestinationConfig, LoggingConfig};
use log::LevelFilter;

const LOG_DEFAULT_LEVEL: LevelFilter = LevelFilter::Info;

#[derive(Debug, Parser)]
struct CliArgs {
    // Use this to add the log flags to your application
    #[clap(flatten)]
    log: clap_logflag::LogArgs,
}

fn main() {
    let args = CliArgs::parse();

    // Initialize logging with the flags from clap
    clap_logflag::init_logging!(
        args.log
            // If no `--log` arguments are present, log to stderr with the default level filter
            // Note that if the user passes in `--log none`, this will not trigger the default
            // and logging will be disabled instead. The default is only used if no `--log`
            // arguments are present.
            .or_default(LoggingConfig::new(vec![LogDestinationConfig {
                destination: clap_logflag::LogDestination::Stderr,
                level: None,
            }],)),
        LOG_DEFAULT_LEVEL
    );

    // Issue some log messages
    log::trace!("Some trace log");
    log::debug!("Some debug log");
    log::info!("Some info log");
    log::warn!("Some warn log");
    log::error!("Some error log");
}