use std::sync::Arc;
#[allow(unused)]
trait SecuroLogger: Send + Sync {
fn info(&self, msg: &str);
fn debug(&self, msg: &str);
fn warn(&self, msg: &str);
fn error(&self, msg: &str);
fn trace(&self, msg: &str);
}
struct NullLogger;
impl SecuroLogger for NullLogger {
fn info(&self, _msg: &str) {}
fn warn(&self, _msg: &str) {}
fn error(&self, _msg: &str) {}
fn debug(&self, _msg: &str) {}
fn trace(&self, _msg: &str) {}
}
struct TracingLogger;
impl SecuroLogger for TracingLogger {
fn info(&self, msg: &str) {
tracing::info!("{}", msg);
}
fn warn(&self, msg: &str) {
tracing::warn!("{}", msg);
}
fn error(&self, msg: &str) {
tracing::error!("{}", msg);
}
fn debug(&self, msg: &str) {
tracing::debug!("{}", msg);
}
fn trace(&self, msg: &str) {
tracing::trace!("{}", msg);
}
}
pub struct LoggerHandle {
logger: Arc<dyn SecuroLogger>,
}
#[allow(unused)]
impl LoggerHandle {
pub fn null() -> Self {
LoggerHandle {
logger: Arc::new(NullLogger),
}
}
pub fn tracing() -> Self {
LoggerHandle {
logger: Arc::new(TracingLogger),
}
}
pub(crate) fn info(&self, msg: &str) {
self.logger.info(msg);
}
pub(crate) fn warn(&self, msg: &str) {
self.logger.warn(msg);
}
pub(crate) fn error(&self, msg: &str) {
self.logger.error(msg);
}
pub(crate) fn debug(&self, msg: &str) {
self.logger.debug(msg);
}
pub(crate) fn trace(&self, msg: &str) {
self.logger.trace(msg);
}
}
macro_rules! linfo {
($logger:expr, $($arg:tt)*) => {
$logger.info(&format!($($arg)*))
};
}
macro_rules! ldebug {
($logger:expr, $($arg:tt)*) => {
$logger.debug(&format!($($arg)*))
};
}
#[allow(unused)]
macro_rules! lwarn {
($logger:expr, $($arg:tt)*) => {
$logger.warn(&format!($($arg)*))
};
}
#[allow(unused)]
macro_rules! lerror {
($logger:expr, $($arg:tt)*) => {
$logger.error(&format!($($arg)*))
};
}
#[allow(unused)]
macro_rules! ltrace {
($logger:expr, $($arg:tt)*) => {
$logger.trace(&format!($($arg)*))
};
}
impl Clone for LoggerHandle {
fn clone(&self) -> Self {
LoggerHandle {
logger: self.logger.clone(),
}
}
}
pub(crate) use linfo;
pub(crate) use ldebug;
#[allow(unused)]
pub(crate) use lwarn;
#[allow(unused)]
pub(crate) use lerror;
#[allow(unused)]
pub(crate) use ltrace;