use crate::{Log, is_heartbeat};
#[derive(Debug, Clone, Copy)]
pub struct TracingLogOptions {
pub include_heartbeats: bool,
}
impl Default for TracingLogOptions {
fn default() -> Self {
Self {
include_heartbeats: true,
}
}
}
pub struct TracingLog {
options: TracingLogOptions,
}
impl Default for TracingLog {
fn default() -> Self {
Self::new()
}
}
impl TracingLog {
pub fn new() -> Self {
Self::with_options(TracingLogOptions::default())
}
pub fn with_options(options: TracingLogOptions) -> Self {
Self { options }
}
}
impl Log for TracingLog {
fn on_incoming(&self, message: &str) {
if is_heartbeat(message) && !self.options.include_heartbeats {
return;
}
tracing::info!(target: "truefix::message", direction = "incoming", %message);
}
fn on_outgoing(&self, message: &str) {
if is_heartbeat(message) && !self.options.include_heartbeats {
return;
}
tracing::info!(target: "truefix::message", direction = "outgoing", %message);
}
fn on_event(&self, text: &str) {
tracing::info!(target: "truefix::event", %text);
}
}