.
//
//!
//! # Mock Handler
//!
//! Returned as Default for Custom handler that is missing.
//!
use crate::*;
use ::{
,
::{self,},
};
///
/// This is used as a _fake_ or _mock_ handler.
///
/// It is a filler for `Handler::Custom(label).create()`. It is also used
/// in examples for custom handlers.
///
#[derive(,)]
pub struct MockHandler {}
impl ::for MockHandler {
fn fmt(&selff: &mut ::<_>) -> :: {
write!( "MockHandler!!")
}
}
impl for MockHandler {
fn create(_name: &str) -> <Self>
where
Self:
{
Ok(Default::())
}
///
/// This is a 'NoOp' fn.
///
fn close(&mut self) {}
///
/// This is a 'NoOp' fn.
///
fn flush(&mut self) {}
fn get_formatter(&self) -> {
Default::()
}
fn get_log(&self) -> {
Default::()
}
///
/// This is always `false`.
///
fn is_open(&self) -> bool {
false
}
#[allow()]
fn publish(&mut self_log_entry: &) {}
fn set_formatter(&mut self_formatter:) {}
///
/// This is a 'NoOp' fn.
///
fn set_test_mode(&mut self_state: bool) {}
}
#[cfg()]
mod tests {
use super::*;
use crate::{,,};
#[test]
fn handler_trait() {
let mut= ::(
module_path!(),
"Mock",
Box::(::(module_path!())unwrap()),
);
// println!("{log}");
assert_eq!("flogging::handlers::mock_handler::tests:: - [INFO]\n\nHandler::Custom(Mock): MockHandler!!\n\n"to_string(),to_string());
info("trait methods");
warning("The sky is falling!");
let=
get_handler(crate::::("Mock"to_string()))
unwrap();
set_test_mode(true);
assert!(!is_open());
set_formatter(::create(None));
assert_eq!(
get_formatter()to_string(),
"dt_fmt: \"\" - fmt_string: \"{mod_path}->{fn_name} [{level:7}] {message}\""
to_string()
);
assert_eq!(get_log(), ""to_string());
flush();
assert_eq!(get_log(), ""to_string());
close();
}
}