Crate verbosio

Crate verbosio 

Source
Expand description

§verbosio

A lightweight, macro-based logging utility for CLI tools and scripts. Designed for ergonomics, speed, and minimal dependencies — with optional ANSI-colored output and terminal spinners.

§Features

  • Global verbosity level
    • Set/get via set_verbosity!, get_verbosity!, or verbose_env!
  • Conditional message printing
    • verbose!, vinfo!, vwarn!, verror!, vebug!
  • Distinct log levels: INFO, WARN, ERROR, DEBUG
  • Optional section headers via vsection!
  • Interactive terminal spinners via status_line! macros
  • Terminal-safe output (no flickering) using crossterm
  • All macros are verbosity-aware (@lvl N)

§Optional Features

  • color: Enables ANSI-colored output (via colored)
  • status: Enables spinner-based status lines using crossterm

§Dependencies

NamePurposeRequired by default
once_cellGlobal static verbosity stateYes
coloredColored output for log levelsNo (color)
crosstermInteractive terminal spinnersNo (status)

§Example

use verbosio::*;

set_verbosity!(2);

verbose!(@lvl 1, "Hello World!");           // printed
vinfo!("App started.");                     // [INFO] App started.
vwarn!(@lvl 3, "This won't show.");         // not printed
verror!("Something went wrong");            // [ERROR] Something went wrong

§Environment Support

You can also set verbosity via the VERBOSE environment variable:

use verbosio::verbose_env;
unsafe {std::env::set_var("VERBOSE", "2");}
verbose_env!(); // Sets verbosity to 2

§Status Line Example (feature = "status")

use verbosio::{status_line, status_line_done};

if let Some(spinner) = status_line!("Building project…") {
    // Simulate work
    std::thread::sleep(std::time::Duration::from_secs(2));
    spinner.stop();
    status_line_done!("Build complete.");
}

§Section Headers

use verbosio::vsection;

vsection!("Step 1: Preparation");
vsection!(@lvl 3, "Step 2: {:?}", "Details"); // only printed if verbosity ≥ 3

§Debug-Only Output

use verbosio::vebug;

vebug!("Always shown in debug mode.");
vebug!(@lvl 3, "Detailed: {:?}", "info"); // only if verbosity ≥ 3

§Philosophy

verbosio is built to be ultra-lightweight and practical for CLI tooling, build scripts, and low-dependency utilities — with structured logging, and configurable verbosity.

§Performance Note

vebug! uses #[cfg(debug_assertions)] and is completely removed in release builds. All other macros like verbose! and status_line! still check verbosity at runtime.

Re-exports§

pub use macros::verbosity::*;
pub use macros::terminal::*;
pub use util::*;

Modules§

macros
util

Macros§

get_verbosity
Retrieves the current global verbosity level.
set_verbosity
Sets the global verbosity level.
vebug
Prints a [DEBUG] message to stdout if in debug mode.
verbose
Prints a message to stdout if the verbosity is high enough.
verbose_env
Sets verbosity level based on the VERBOSE environment variable.
verror
Prints an [ERROR] message to stderr if the verbosity is high enough.
vinfo
Prints an [INFO] message to stdout if the verbosity is high enough.
vsection
Prints a formatted section header if the verbosity level is high enough.
vwarn
Prints a [WARN] message to stdout if the verbosity is high enough.

Statics§

VERBOSE