While external loggers can be used, if you are compiling with --features use_std, then it will default to just printing everything to the stdout unless a logger is created. This library can be used without the STD library, however, you will have to write an external logger.
111 lines
1.7 KiB
Rust
111 lines
1.7 KiB
Rust
#[macro_use]
|
|
extern crate scribe;
|
|
|
|
|
|
|
|
use scribe::{Levels, Logger, Record};
|
|
|
|
|
|
|
|
pub struct TestLogger
|
|
{
|
|
}
|
|
|
|
impl TestLogger
|
|
{
|
|
pub fn start()
|
|
{
|
|
match scribe::set_logger(TestLogger::set_logger)
|
|
{
|
|
Ok(_) =>
|
|
{
|
|
println!("Logger sucessfully set.");
|
|
}
|
|
|
|
Err(error) =>
|
|
{
|
|
println!("ERROR: {}", error);
|
|
}
|
|
}
|
|
}
|
|
|
|
pub fn stop()
|
|
{
|
|
match scribe::clear_logger()
|
|
{
|
|
Ok(_) =>
|
|
{
|
|
println!("Logger cleared.");
|
|
}
|
|
|
|
Err(error) =>
|
|
{
|
|
println!("ERROR: {}", error);
|
|
}
|
|
}
|
|
}
|
|
|
|
fn set_logger() -> Box<Logger>
|
|
{
|
|
let logger: TestLogger;
|
|
|
|
logger =
|
|
TestLogger
|
|
{
|
|
};
|
|
|
|
Box::new(logger)
|
|
}
|
|
}
|
|
|
|
impl Logger for TestLogger
|
|
{
|
|
fn is_domain_enabled(&self, domain_name: &'static str) -> bool
|
|
{
|
|
println!("Domain '{}': {}", domain_name, true);
|
|
true
|
|
}
|
|
|
|
fn is_level_enabled(&self, lvl: Levels) -> bool
|
|
{
|
|
println!("Level '{}': {}", lvl, true);
|
|
true
|
|
}
|
|
|
|
fn log(&self, record: &Record)
|
|
{
|
|
println!("Record: {}", record);
|
|
}
|
|
}
|
|
|
|
|
|
mod temp_mod
|
|
{
|
|
pub fn print()
|
|
{
|
|
info!("Mod test.");
|
|
}
|
|
}
|
|
|
|
pub fn main()
|
|
{
|
|
TestLogger::start();
|
|
|
|
temp_mod::print();
|
|
|
|
debug!("This seemed to work alright.");
|
|
debug!(domain: "Temp Domain", "This seemed to work alright.");
|
|
|
|
info!("Jason is awesome.");
|
|
info!(domain: "Temp Domain", "Jason is awesome.");
|
|
|
|
warn!("Danger Will Robinson, danger!");
|
|
warn!(domain: "Temp Domain", "Danger Will Robinson, danger!");
|
|
|
|
//error!("There was an error!");
|
|
//error!(domain: "Temp Domain", "There was an error!");
|
|
|
|
|
|
TestLogger::stop();
|
|
}
|