scribe/examples/logger.rs
Myrddin Dundragon 45efdb8ccb [#1] Updated the library to compile for Rust 2021.
This was mostly an issue of changing the way Trait objects were
implemented now that you are supposed to use the dyn keyword.

Also changed some atomic operations to use the new non-deprecated
functions.
2025-02-19 19:47:37 -05:00

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<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();
}