use super::{LogLevel, LogRecord, LogWriter};
pub struct TracingLogWriter {
max_level: LogLevel,
}
impl TracingLogWriter {
pub fn new(max_level: LogLevel) -> Self {
Self { max_level }
}
}
impl LogWriter for TracingLogWriter {
fn write_log(&self, record: &LogRecord) {
if record.level >= self.max_level {
let module_path = record.module_path.as_deref().unwrap_or(&record.target);
match record.level {
LogLevel::Trace => tracing::trace!(
message = record.message,
module = module_path,
timestamp = record.timestamp.to_utc().timestamp_millis(),
),
LogLevel::Debug => tracing::debug!(
message = record.message,
module = module_path,
timestamp = record.timestamp.to_utc().timestamp_millis(),
),
LogLevel::Info => tracing::info!(
message = record.message,
module = module_path,
timestamp = record.timestamp.to_utc().timestamp_millis(),
),
LogLevel::Warn => tracing::warn!(
message = %record.message,
module = module_path,
timestamp = record.timestamp.to_utc().timestamp_millis(),
),
LogLevel::Error => tracing::error!(
message = record.message,
module = module_path,
timestamp = record.timestamp.to_utc().timestamp_millis(),
),
};
};
}
fn flush(&self) {
}
}