use std::fmt;
#[allow(dead_code)]
pub struct Temp {
val: String,
}
#[allow(dead_code)]
impl Temp {
pub fn new(val: String) -> Self {
Self { val }
}
pub fn val(&self) -> String {
self.val.clone()
}
}
impl fmt::Display for Temp {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
self.val.fmt(f)
}
}
#[cfg(test)]
mod tests {
use chrono::Local;
use flogging::*;
const_logger!({
Logger::builder("flogging")
.add_console_handler()
.remove_file("tests/it_conversion.log")
.add_file_handler("tests/it_conversion.log")
.add_string_handler()
.set_level(Level::FINEST)
.build()
});
#[logger]
#[test]
fn my_func() {
config!("Some text to store.");
let time = Local::now();
config!("The configuration as at: {}", time);
config!("The configuration as at: {time}");
config!("The configuration as at: {time:?}");
}
#[logger]
#[test]
fn format() {
let arg = "Serious stuff".to_string();
let arg1 = "NOW!!".to_string();
let arg2 = "Signed: Brad".to_string();
config!("Testing `config` macro: {}, {} ({})", arg, arg1, arg2);
fine!("Testing `fine` macro: {}, {} ({})", arg, arg1, arg2);
finer!("Testing `finer` macro: {}, {} ({})", arg, arg1, arg2);
finest!("Testing `finest` macro: {}, {} ({})", arg, arg1, arg2);
info!("Testing `info` macro: {}, {} ({})", arg, arg1, arg2);
warning!("Testing `warning` macro: {}, {} ({})", arg, arg1, arg2);
severe!("Testing `severe` macro: {}, {} ({})", arg, arg1, arg2);
}
#[logger]
#[test]
fn format2() {
use super::Temp;
let arg = "Serious stuff".to_string();
let arg1 = "NOW!!".to_string();
let arg2 = "Signed: Brad".to_string();
config!("arg: {arg} {} ({})", arg1, arg2);
config!(arg, arg1, arg2);
let temp = Temp::new("Freddy".to_string());
info!(temp);
}
#[logger]
#[test]
fn string_log() {
info!("Some text to store.");
warning!("Rain is wet!");
severe!("Hurricanes are windy!");
if let Some(h) = get_handler!(Handler::String) {
println!(
"\n(h.get_log())\n======v======\n{}\n======^======",
h.get_log()
);
} else {
println!("Sorry. Not there!");
}
}
#[logger]
#[test]
fn empty_msg() {
info!();
}
#[test]
#[logger]
fn is_logging() {
assert!(is_logging!());
set_level!(Level::OFF);
assert!(!is_logging!());
}
}