Crates.io | simplog |
lib.rs | simplog |
version | 1.6.0 |
source | src |
created_at | 2018-02-04 16:52:04.878096 |
updated_at | 2022-11-29 19:20:50.826796 |
description | An extremely small and simple logger to stdout/stderr, with controllable levels of verbosity |
homepage | https://github.com/andrewdavidmackenzie/simplog/blob/master/README.md |
repository | https://github.com/andrewdavidmackenzie/simplog |
max_upload_size | |
id | 49615 |
size | 13,673 |
A small and easy to use rust crate for logging.
## Add to your project
Add the dependency on simplog
in your crate's Cargo.toml
file:
[dependencies]
simplog = "~1.2"
Import the simplog crate in your code, and use the SimpleLogger module.
extern crate simplog;
use simplog::simplog::SimpleLogger;
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 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;
#[macro_use]
extern crate log;
extern crate simplog;
use simplog::simplog::SimpleLogger;
fn main() {
SimpleLogger::init(Some("Info"));
info!("Hello World!");
}