2 releases

0.2.1 Jun 6, 2023
0.2.0 Jun 5, 2023

#14 in #verbose

Download history 8/week @ 2024-02-23 5/week @ 2024-03-01 2/week @ 2024-03-22 65/week @ 2024-03-29

67 downloads per month

MIT license

15KB
196 lines

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

}


Dependencies

~1–10MB
~75K SLoC