use async_trait::async_trait;
#[async_trait]
pub trait Logger: Send + Sync {
async fn info(&self, msg: &str);
async fn error(&self, msg: &str);
}
pub struct StdLogger {
show_info: bool,
show_error: bool,
}
impl StdLogger {
pub fn new(show_info: bool, show_error: bool) -> Self {
Self {
show_info,
show_error,
}
}
}
#[async_trait]
impl Logger for StdLogger {
async fn info(&self, msg: &str) {
if self.show_info {
println!("[INFO] {}", msg);
}
}
async fn error(&self, msg: &str) {
if self.show_error {
eprintln!("[ERROR] {}", msg);
}
}
}
pub struct NoOpLogger;
impl NoOpLogger {
pub fn new() -> Self {
Self
}
}
impl Default for NoOpLogger {
fn default() -> Self {
Self::new()
}
}
#[async_trait]
impl Logger for NoOpLogger {
async fn info(&self, _msg: &str) {
}
async fn error(&self, _msg: &str) {
}
}