stump

Crates.iostump
lib.rsstump
version0.2.1
sourcesrc
created_at2023-06-05 02:57:55.913831
updated_at2023-06-06 01:08:29.472873
descriptionSimplified command line logging
homepage
repositoryhttps://github.com/kmgill/stump
max_upload_size
id882722
size15,201
Kevin M. Gill (kmgill)

documentation

README

Stump

Stump is a very simple console logging library.

Application-set Logging Level

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 ...
}

Environment variable control:

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.

Logging

debug!("Kevin is");
info!("bad at");
warn!("writing documentation");
error!("for OSS projects");

Task Completion Messages

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 ]

General Purpose Verbose (or not) Printing

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");

Overriding Stdout

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);
    });

}


Commit count: 13

cargo fmt