This will bring the library into compliance with the new Rust 2021 version. This was a simple change of how trait objects are done.
121 lines
1.9 KiB
Rust
121 lines
1.9 KiB
Rust
use scribe::{debug, info, warn};
|
|
use scribe::{Levels, Logger, Record};
|
|
|
|
|
|
|
|
#[cfg(not(feature="use_std"))]
|
|
const CORE_LOGGER: TestLogger = TestLogger {};
|
|
|
|
|
|
|
|
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);
|
|
}
|
|
}
|
|
}
|
|
|
|
#[cfg(feature="use_std")]
|
|
fn set_logger() -> Box<dyn Logger>
|
|
{
|
|
let logger: TestLogger;
|
|
|
|
logger =
|
|
TestLogger
|
|
{
|
|
};
|
|
|
|
Box::new(logger)
|
|
}
|
|
|
|
#[cfg(not(feature="use_std"))]
|
|
fn set_logger() -> *const dyn Logger
|
|
{
|
|
&CORE_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
|
|
{
|
|
use scribe::info;
|
|
|
|
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();
|
|
}
|