tracing_systemd/systemd_layer/
impls.rs

1use crate::SystemdLayer;
2
3impl SystemdLayer {
4    ///Creates a new `SystemdLayer` with default configuration.
5    pub fn new() -> Self {
6        Self {
7            log_thread_id: false,
8            span_separator: "::",
9            message_separator: ": ",
10            log_target: false,
11            function_bracket_left: "(",
12            function_bracket_right: ")",
13            arguments_equality: ": ",
14            arguments_separator: ", ",
15            use_level_prefix: true,
16            level_separator: " ",
17            thread_id_prefix: "[",
18            thread_id_suffix: "] ",
19
20            #[cfg(feature = "sd-journal")]
21            use_sd_journal: true,
22            #[cfg(feature = "colored")]
23            use_color: true,
24        }
25    }
26
27    ///Sets whether or not to include thread IDs (default: false)
28    pub fn with_thread_ids(self, log_thread_id: bool) -> Self {
29        Self {
30            log_thread_id,
31            ..self
32        }
33    }
34
35    ///Sets the span separator (default: "::")
36    pub fn separate_spans_with(self, span_separator: &'static str) -> Self {
37        Self {
38            span_separator,
39            ..self
40        }
41    }
42
43    ///Sets the message separator (default: ": ")
44    pub fn separate_message_with(self, message_separator: &'static str) -> Self {
45        Self {
46            message_separator,
47            ..self
48        }
49    }
50
51    ///Sets whether or not to include the target (default: false)
52    pub fn with_target(self, display_target: bool) -> Self {
53        Self {
54            log_target: display_target,
55            ..self
56        }
57    }
58
59    ///Sets the left bracket for function names (default: "(")
60    pub fn function_bracket_left(self, function_bracket_left: &'static str) -> Self {
61        Self {
62            function_bracket_left,
63            ..self
64        }
65    }
66
67    ///Sets the right bracket for function names (default: ")")
68    pub fn function_bracket_right(self, function_bracket_right: &'static str) -> Self {
69        Self {
70            function_bracket_right,
71            ..self
72        }
73    }
74
75    ///Sets the equality sign for arguments (default: ": ")
76    pub fn arguments_equality(self, arguments_equality: &'static str) -> Self {
77        Self {
78            arguments_equality,
79            ..self
80        }
81    }
82
83    ///Sets the separator for arguments (default: ", ")
84    pub fn arguments_separator(self, arguments_separator: &'static str) -> Self {
85        Self {
86            arguments_separator,
87            ..self
88        }
89    }
90
91    ///Sets the separator for levels (default: " ")
92    pub fn level_separator(self, level_separator: &'static str) -> Self {
93        Self {
94            level_separator,
95            ..self
96        }
97    }
98
99    ///Sets the prefix for thread IDs (default: "[")
100    pub fn thread_id_prefix(self, thread_id_prefix: &'static str) -> Self {
101        Self {
102            thread_id_prefix,
103            ..self
104        }
105    }
106
107    ///Sets the suffix for thread IDs (default: "] ")
108    pub fn thread_id_suffix(self, thread_id_suffix: &'static str) -> Self {
109        Self {
110            thread_id_suffix,
111            ..self
112        }
113    }
114
115    ///Sets whether or not to use sd_journal to write logs (default: true)
116    #[cfg(feature = "sd-journal")]
117    pub fn use_sd_journal(self, use_sd_journal: bool) -> Self {
118        Self {
119            use_sd_journal,
120            ..self
121        }
122    }
123
124    ///Sets whether or not to use level prefixes (default: true)
125    pub fn use_level_prefix(self, use_level_prefix: bool) -> Self {
126        Self {
127            use_level_prefix,
128            ..self
129        }
130    }
131
132    ///Sets whether or not to use color
133    #[cfg(feature = "colored")]
134    pub fn use_color(self, use_color: bool) -> Self {
135        Self { use_color, ..self }
136    }
137}
138
139impl SystemdLayer {
140    pub(crate) fn get_log_thread_id(&self) -> bool {
141        self.log_thread_id
142    }
143
144    pub(crate) fn get_span_separator(&self) -> &'static str {
145        self.span_separator
146    }
147
148    pub(crate) fn get_message_separator(&self) -> &'static str {
149        self.message_separator
150    }
151
152    pub(crate) fn get_log_target(&self) -> bool {
153        self.log_target
154    }
155
156    pub(crate) fn get_function_bracket_left(&self) -> &'static str {
157        self.function_bracket_left
158    }
159
160    pub(crate) fn get_function_bracket_right(&self) -> &'static str {
161        self.function_bracket_right
162    }
163
164    pub(crate) fn get_arguments_equality(&self) -> &'static str {
165        self.arguments_equality
166    }
167
168    pub(crate) fn get_arguments_separator(&self) -> &'static str {
169        self.arguments_separator
170    }
171
172    #[cfg(feature = "sd-journal")]
173    pub(crate) fn get_use_sd_journal(&self) -> bool {
174        self.use_sd_journal
175    }
176
177    pub(crate) fn get_use_level_prefix(&self) -> bool {
178        self.use_level_prefix
179    }
180
181    pub(crate) fn get_level_separator(&self) -> &'static str {
182        self.level_separator
183    }
184
185    #[cfg(feature = "colored")]
186    pub(crate) fn get_use_color(&self) -> bool {
187        self.use_color
188    }
189
190    pub(crate) fn get_thread_id_prefix(&self) -> &'static str {
191        self.thread_id_prefix
192    }
193
194    pub(crate) fn get_thread_id_suffix(&self) -> &'static str {
195        self.thread_id_suffix
196    }
197}