use std::fmt;
pub struct PluginLogger {
target: String,
}
impl PluginLogger {
pub fn new(plugin_name: &str) -> Self {
Self {
target: format!("basalt::plugin::{plugin_name}"),
}
}
pub fn error(&self, msg: impl fmt::Display) {
log::log!(target: &self.target, log::Level::Error, "{msg}");
}
pub fn warn(&self, msg: impl fmt::Display) {
log::log!(target: &self.target, log::Level::Warn, "{msg}");
}
pub fn info(&self, msg: impl fmt::Display) {
log::log!(target: &self.target, log::Level::Info, "{msg}");
}
pub fn debug(&self, msg: impl fmt::Display) {
log::log!(target: &self.target, log::Level::Debug, "{msg}");
}
pub fn trace(&self, msg: impl fmt::Display) {
log::log!(target: &self.target, log::Level::Trace, "{msg}");
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn logger_target_format() {
let logger = PluginLogger::new("chat");
assert_eq!(logger.target, "basalt::plugin::chat");
}
#[test]
fn logger_does_not_panic() {
let logger = PluginLogger::new("test");
logger.error("test error");
logger.warn("test warn");
logger.info("test info");
logger.debug("test debug");
logger.trace("test trace");
}
}