https://github.com/passcod/lloggs
Logging configuration for clap applications
https://github.com/passcod/lloggs
Last synced: 6 months ago
JSON representation
Logging configuration for clap applications
- Host: GitHub
- URL: https://github.com/passcod/lloggs
- Owner: passcod
- License: apache-2.0
- Created: 2025-02-03T00:58:29.000Z (12 months ago)
- Default Branch: main
- Last Pushed: 2025-04-29T00:12:35.000Z (9 months ago)
- Last Synced: 2025-07-21T08:28:14.114Z (6 months ago)
- Language: Rust
- Homepage:
- Size: 36.1 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE-APACHE
Awesome Lists containing this project
README
# lloggs
Logging configuration for [clap](https://docs.rs/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](https://docs.rs/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 (), and adjusts defaults when it detects systemd.
- **[API documentation](https://docs.rs/lloggs)**.
- Licensed under [Apache 2.0](./LICENSE-APACHE) or [MIT](./LICENSE-MIT).
# Example
```rust
use lloggs::{LoggingArgs, PreArgs};
use clap::Parser;
#[derive(Debug, Parser)]
struct Args {
#[command(flatten)]
logging: LoggingArgs,
// Your other arguments here
}
fn main() -> Result<(), Box> {
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(())
}
```