truefix_log/
tracing_log.rs1use crate::{Log, is_heartbeat};
4
5#[derive(Debug, Clone, Copy)]
9pub struct TracingLogOptions {
10 pub include_heartbeats: bool,
12}
13
14impl Default for TracingLogOptions {
15 fn default() -> Self {
16 Self {
17 include_heartbeats: true,
18 }
19 }
20}
21
22pub struct TracingLog {
24 options: TracingLogOptions,
25}
26
27impl Default for TracingLog {
28 fn default() -> Self {
29 Self::new()
30 }
31}
32
33impl TracingLog {
34 pub fn new() -> Self {
36 Self::with_options(TracingLogOptions::default())
37 }
38
39 pub fn with_options(options: TracingLogOptions) -> Self {
41 Self { options }
42 }
43}
44
45impl Log for TracingLog {
46 fn on_incoming(&self, message: &str) {
47 if is_heartbeat(message) && !self.options.include_heartbeats {
48 return;
49 }
50 tracing::info!(target: "truefix::message", direction = "incoming", %message);
51 }
52 fn on_outgoing(&self, message: &str) {
53 if is_heartbeat(message) && !self.options.include_heartbeats {
54 return;
55 }
56 tracing::info!(target: "truefix::message", direction = "outgoing", %message);
57 }
58 fn on_event(&self, text: &str) {
59 tracing::info!(target: "truefix::event", %text);
60 }
61}