Crates.io | stump |
lib.rs | stump |
version | 0.2.1 |
source | src |
created_at | 2023-06-05 02:57:55.913831 |
updated_at | 2023-06-06 01:08:29.472873 |
description | Simplified command line logging |
homepage | |
repository | https://github.com/kmgill/stump |
max_upload_size | |
id | 882722 |
size | 15,201 |
Stump is a very simple console logging library.
The application can use Stump's set_min_log_level
function call to set the globally used log level. This, however, can be user-overridden using environment variables.
#[macro_use]
extern crate stump;
fn main() {
stump::set_min_log_level(stump::LogEntryLevel::INFO);
info!("Initialized logging");
// Application logic ...
}
STUMP_LOG_AT_LEVEL = DEBUG | INFO | WARN | ERROR
STUMP_LOG_DATETIME_FORMAT = "%Y-%m-%d %H:%M:%S%.3f"
See https://docs.rs/chrono/latest/chrono/ for date & time formatting.
debug!("Kevin is");
info!("bad at");
warn!("writing documentation");
error!("for OSS projects");
Stump also provides functions for printing task completion status messages.
stump::print_done("Some process finished");
// Some process finished [ DONE ]
stump::print_warn("Some process with warnings");
// Some process with warnings [ WARN ]
stump::print_fail("Some process failed");
// Some process failed [ FAIL ]
For a general purpose version of Rust's println
and eprintln
that respects a global verbosity setting.
vprintln!("This won't print as the default is false");
stump::set_verbose(true);
// print to stdout
vprintln!("Print something {}", "Here");
// print to stderr
veprintln!("Print something {}", "Here");
stump::set_verbose(false);
// Don't print to stdout
vprintln("Again nothing will print");
When integrating stump with another CLI library, such as indicatif
, you can provide another means of printing, such as to
route the output through their print method:
use indicatif::ProgressBar;
use stump;
lazy_static! {
static ref PB: ProgressBar = ProgressBar::new(1);
}
fn main() {
stump::set_print(|s| {
PB.println(s);
});
}