#logging #cargo-toml #level #log

simplog

An extremely small and simple logger to stdout/stderr, with controllable levels of verbosity

12 stable releases

1.6.0 Nov 29, 2022
1.5.0 Apr 26, 2022
1.3.0 Sep 18, 2019
1.1.1 Apr 3, 2019
1.0.2 Feb 20, 2018

#153 in Debugging

Download history 74/week @ 2023-06-06 77/week @ 2023-06-13 144/week @ 2023-06-20 121/week @ 2023-06-27 229/week @ 2023-07-04 147/week @ 2023-07-11 230/week @ 2023-07-18 225/week @ 2023-07-25 168/week @ 2023-08-01 300/week @ 2023-08-08 206/week @ 2023-08-15 121/week @ 2023-08-22 135/week @ 2023-08-29 123/week @ 2023-09-05 240/week @ 2023-09-12 112/week @ 2023-09-19

647 downloads per month
Used in 5 crates (2 directly)

MIT license

11KB
122 lines

Build Status

simplog

A small and easy to use rust crate for logging.

## Add to your project Add the dependency on simplogin your crate's Cargo.tomlfile:

[dependencies]
simplog = "~1.2"

Importing

Import the simplog crate in your code, and use the SimpleLogger module.

extern crate simplog;
use simplog::simplog::SimpleLogger;

Initializing

Initialize the SimpleLogger using the init() function by passing it an Option<&str> that has a value of None or Some("log_level_str"), where log_level_str is a &str with a valid log level, in any case.

The string will be parsed and if valid set as the log level.

SimpleLogger::init(Some("Info"));

or if you do not want the Log Level prefix printed at the start of each line, initialize thus:

SimpleLogger::init_prefix(Some("Info"), false);

Logging

Logging is done using the normal rust log framework, with it's macros for easily logging at different levels: error!(), info!(), etc.

To include the rust logging framework in your project, add a dependency to your Cargo.toml:

[dependencies]
log = "0.3.8"

and use the crate in your code with:

#[macro_use]   
 extern crate log;

Example

#[macro_use]
extern crate log;

extern crate simplog;
use simplog::simplog::SimpleLogger;

fn main() {
    SimpleLogger::init(Some("Info"));
    info!("Hello World!");
}

Dependencies

~120–345KB