Struct simplog::SimpleLogger
source · pub struct SimpleLogger { /* private fields */ }
Expand description
Use the SimpleLogger
struct to initialize a logger. From then on, the rust log
framework
should be used to output log statements as usual.
Example
use log::{info, error};
use simplog::SimpleLogger;
SimpleLogger::init(None); // Log level defaults to `Error`
info!("Hello World!");
// Produces nothing
error!("Goodbye World!");
// Produces "Goodbye World"
Implementations§
source§impl SimpleLogger
impl SimpleLogger
sourcepub fn init(verbosity: Option<&str>)
pub fn init(verbosity: Option<&str>)
Initialize the logger, with an optionally provided log level (verbosity
) in a &str
If None
is provided -> The log level will be set to Error
If ‘Some(`verbosity’) is a &str with a valid log level, the string will be parsed and if
valid set as the log level.
Example
use log::info;
use simplog::SimpleLogger;
SimpleLogger::init(Some("info"));
info!("Hello World!");
// Produces "Hello World"
sourcepub fn init_prefix(verbosity: Option<&str>, prefix: bool)
pub fn init_prefix(verbosity: Option<&str>, prefix: bool)
Initialize the logger, with an optionally provided log level (verbosity
) in a &str
The default log level is Error if None
is provided.
prefix
determines whether each log line output is prefixed with the level that produced it
Example
use log::info;
use simplog::SimpleLogger;
SimpleLogger::init_prefix(Some("info"), true);
info!("Hello World!");
// Produces "INFO - Hello World"
sourcepub fn init_prefix_timestamp(
verbosity: Option<&str>,
prefix: bool,
timestamp: bool
)
pub fn init_prefix_timestamp(
verbosity: Option<&str>,
prefix: bool,
timestamp: bool
)
Initialize the logger, with an optionally provided log level (verbosity
) in a &str
The default log level is Error if None
is provided.
prefix
determines whether each log line output is prefixed with the level that produced it
if timestamp
is true, each log line will be prefixed with the elapsed time since the
logger was initialized
Example
use log::info;
use simplog::SimpleLogger;
let mut logger = SimpleLogger::init_prefix_timestamp(Some("info"), false, true);
info!("Hello World!");
// Produces "1.246717ms Hello World"
Trait Implementations§
source§impl Clone for SimpleLogger
impl Clone for SimpleLogger
source§fn clone(&self) -> SimpleLogger
fn clone(&self) -> SimpleLogger
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read more