Skip to main content

tuwunel_core/log/
mod.rs

1pub mod capture;
2pub mod color;
3pub mod console;
4pub mod fmt;
5pub mod fmt_span;
6mod reload;
7mod suppress;
8
9use std::sync::Arc;
10
11pub use tracing::{Level, subscriber::Subscriber};
12pub use tracing_core::{Event, Metadata};
13pub use tracing_subscriber::EnvFilter;
14
15pub use self::{
16	capture::Capture,
17	console::{ConsoleFormat, ConsoleWriter, is_systemd_mode},
18	reload::{LogLevelReloadHandles, ReloadHandle},
19	suppress::Suppress,
20};
21
22/// Logging subsystem. This is a singleton member of super::Server which holds
23/// all logging and tracing related state rather than shoving it all in
24/// super::Server directly.
25pub struct Logging {
26	/// Subscriber assigned to globals and defaults; may also be NoSubscriber.
27	pub subscriber: Arc<dyn Subscriber + Send + Sync>,
28
29	/// General log level reload handles.
30	pub reload: LogLevelReloadHandles,
31
32	/// Tracing capture state for ephemeral/oneshot uses.
33	pub capture: Arc<capture::State>,
34}
35
36// Wraps for logging macros. Use these macros rather than extern tracing:: or
37// log:: crates in project code. ::log and ::tracing can still be used if
38// necessary but discouraged. Remember debug_ log macros are also exported to
39// the crate namespace like these.
40
41#[macro_export]
42#[collapse_debuginfo(yes)]
43macro_rules! event {
44	( $level:expr_2021, $($x:tt)+ ) => { ::tracing::event!( $level, $($x)+ ) }
45}
46
47#[macro_export]
48macro_rules! error {
49    ( $($x:tt)+ ) => { ::tracing::error!( $($x)+ ) }
50}
51
52#[macro_export]
53macro_rules! warn {
54    ( $($x:tt)+ ) => { ::tracing::warn!( $($x)+ ) }
55}
56
57#[macro_export]
58macro_rules! info {
59    ( $($x:tt)+ ) => { ::tracing::info!( $($x)+ ) }
60}
61
62#[macro_export]
63macro_rules! debug {
64    ( $($x:tt)+ ) => { ::tracing::debug!( $($x)+ ) }
65}
66
67#[macro_export]
68macro_rules! trace {
69    ( $($x:tt)+ ) => { ::tracing::trace!( $($x)+ ) }
70}