verbosio/
lib.rs

1//! # verbosio
2//!
3//! A lightweight, macro-based logging utility for CLI tools and scripts.
4//! Designed for ergonomics, speed, and optional colored output — with minimal dependencies.
5//!
6//! ## Features
7//! - Global verbosity level (via `set_verbosity!`, `get_verbosity!`, `verbose_env!`)
8//! - Print messages conditionally based on verbosity (`verbose!`, `vinfo!`, `vwarn!`, `verror!`)
9//! - Distinct log levels: `INFO`, `WARN`, `ERROR`
10//! - Optional ANSI-colored output via the `color` feature
11//!
12//! ## Dependencies
13//! - [`once_cell`](https://crates.io/crates/once_cell): For global static verbosity state (always included)
14//! - [`colored`](https://crates.io/crates/colored): Optional, behind the `color` feature flag
15//!
16//! ## Example
17//! ```rust
18//! use verbosio::*;
19//!
20//! set_verbosity!(2);
21//!
22//! verbose!(1, "Hello World!");         // printed
23//! vinfo!("App started.");              // [INFO] App started.
24//! vwarn!(3, "This won't show.");       // not printed
25//! verror!("Something went wrong");     // [ERROR] Something went wrong
26//! ```
27//!
28//! ## Environment Support
29//! You can also set verbosity based on the `VERBOSE` environment variable:
30//!
31//! ```rust
32//! use verbosio::verbose_env;
33//! unsafe {std::env::set_var("VERBOSE", "2");}
34//! verbose_env!(); // Sets verbosity to 2
35//! ```
36
37
38pub mod macros;
39pub mod util;
40use once_cell::sync::Lazy;
41use std::sync::atomic::{AtomicU8};
42
43pub static VERBOSE: Lazy<AtomicU8> = Lazy::new(|| AtomicU8::new(0));
44
45/// Re-exports all macros for easy access.
46#[allow(unused_imports)]
47pub use macros::*;
48pub use util::*;