Skip to main content

wp_log/
macro_def.rs

1// 统一日志 target,围绕 6 个域进行输出:
2// ctrl  - 平台控制面,覆盖启动/调度/治理等生命周期事件。
3// data  - 数据平面,覆盖 source/parse/connector/sink 的数据流处理。
4// rule  - 规则与业务策略执行,包含插件/接口等扩展点。
5// dfx   - 诊断与恢复能力,包含容错、兜底、应急处理。
6// mtrc  - 指标与观测数据,记录性能、吞吐、容量等信息。
7// kdb   - 知识库或知识图谱相关逻辑,集中管理特征/上下文。
8//
9// 为保证兼容,旧的 target 宏仍然导出,但已经标记为过期(#[deprecated]),
10// 并在内部转发到新的域。迁移新日志时请直接使用新的 target 宏。
11
12// ctrl 域(平台控制面)
13#[macro_export]
14macro_rules! trace_ctrl { ($($arg:tt)+) => { $crate::re_exports::log::trace!(target: "ctrl", $($arg)+) } }
15#[macro_export]
16macro_rules! debug_ctrl { ($($arg:tt)+) => { $crate::re_exports::log::debug!(target: "ctrl", $($arg)+) } }
17#[macro_export]
18macro_rules! info_ctrl  { ($($arg:tt)+) => { $crate::re_exports::log::info!( target: "ctrl", $($arg)+) } }
19#[macro_export]
20macro_rules! warn_ctrl  { ($($arg:tt)+) => { $crate::re_exports::log::warn!( target: "ctrl", $($arg)+) } }
21#[macro_export]
22macro_rules! error_ctrl { ($($arg:tt)+) => { $crate::re_exports::log::error!(target: "ctrl", $($arg)+) } }
23
24// data 域(数据平面)
25#[macro_export]
26macro_rules! trace_data { ($($arg:tt)+) => { $crate::re_exports::log::trace!(target: "data", $($arg)+) } }
27#[macro_export]
28macro_rules! debug_data { ($($arg:tt)+) => { $crate::re_exports::log::debug!(target: "data", $($arg)+) } }
29#[macro_export]
30macro_rules! info_data  { ($($arg:tt)+) => { $crate::re_exports::log::info!( target: "data", $($arg)+) } }
31#[macro_export]
32macro_rules! warn_data  { ($($arg:tt)+) => { $crate::re_exports::log::warn!( target: "data", $($arg)+) } }
33#[macro_export]
34macro_rules! error_data { ($($arg:tt)+) => { $crate::re_exports::log::error!(target: "data", $($arg)+) } }
35
36// data 域(数据平面)
37#[macro_export]
38macro_rules! trace_edata {
39    ($event_id:expr, $($arg:tt)+) => {
40        $crate::re_exports::log::trace!(target: "data", "[eid:{}] {}", $event_id, format_args!($($arg)+))
41    }
42}
43#[macro_export]
44macro_rules! debug_edata {
45    ($event_id:expr, $($arg:tt)+) => {
46        $crate::re_exports::log::debug!(target: "data", "[eid:{}] {}", $event_id, format_args!($($arg)+))
47    }
48}
49#[macro_export]
50macro_rules! info_edata {
51    ($event_id:expr, $($arg:tt)+) => {
52        $crate::re_exports::log::info!(target: "data", "[eid:{}] {}", $event_id, format_args!($($arg)+))
53    }
54}
55#[macro_export]
56macro_rules! warn_edata {
57    ($event_id:expr, $($arg:tt)+) => {
58        $crate::re_exports::log::warn!(target: "data", "[eid:{}] {}", $event_id, format_args!($($arg)+))
59    }
60}
61#[macro_export]
62macro_rules! error_edata {
63    ($event_id:expr, $($arg:tt)+) => {
64        $crate::re_exports::log::error!(target: "data", "[eid:{}] {}", $event_id, format_args!($($arg)+))
65    }
66}
67
68// rule 域(策略/插件/接口)
69#[macro_export]
70macro_rules! trace_rule { ($($arg:tt)+) => { $crate::re_exports::log::trace!(target: "rule", $($arg)+) } }
71#[macro_export]
72macro_rules! debug_rule { ($($arg:tt)+) => { $crate::re_exports::log::debug!(target: "rule", $($arg)+) } }
73#[macro_export]
74macro_rules! info_rule  { ($($arg:tt)+) => { $crate::re_exports::log::info!( target: "rule", $($arg)+) } }
75#[macro_export]
76macro_rules! warn_rule  { ($($arg:tt)+) => { $crate::re_exports::log::warn!( target: "rule", $($arg)+) } }
77#[macro_export]
78macro_rules! error_rule { ($($arg:tt)+) => { $crate::re_exports::log::error!(target: "rule", $($arg)+) } }
79
80// dfx 域(诊断 & 恢复)
81#[macro_export]
82macro_rules! trace_dfx { ($($arg:tt)+) => { $crate::re_exports::log::trace!(target: "dfx", $($arg)+) } }
83#[macro_export]
84macro_rules! debug_dfx { ($($arg:tt)+) => { $crate::re_exports::log::debug!(target: "dfx", $($arg)+) } }
85#[macro_export]
86macro_rules! info_dfx  { ($($arg:tt)+) => { $crate::re_exports::log::info!( target: "dfx", $($arg)+) } }
87#[macro_export]
88macro_rules! warn_dfx  { ($($arg:tt)+) => { $crate::re_exports::log::warn!( target: "dfx", $($arg)+) } }
89#[macro_export]
90macro_rules! error_dfx { ($($arg:tt)+) => { $crate::re_exports::log::error!(target: "dfx", $($arg)+) } }
91
92// mtrc 域(指标 & 观测)
93#[macro_export]
94macro_rules! trace_mtrc { ($($arg:tt)+) => { $crate::re_exports::log::trace!(target: "mtrc", $($arg)+) } }
95#[macro_export]
96macro_rules! debug_mtrc { ($($arg:tt)+) => { $crate::re_exports::log::debug!(target: "mtrc", $($arg)+) } }
97#[macro_export]
98macro_rules! info_mtrc  { ($($arg:tt)+) => { $crate::re_exports::log::info!( target: "mtrc", $($arg)+) } }
99#[macro_export]
100macro_rules! warn_mtrc  { ($($arg:tt)+) => { $crate::re_exports::log::warn!( target: "mtrc", $($arg)+) } }
101#[macro_export]
102macro_rules! error_mtrc { ($($arg:tt)+) => { $crate::re_exports::log::error!(target: "mtrc", $($arg)+) } }
103
104#[macro_export]
105macro_rules! println_mtrc {
106    ($($arg:tt)+) => {
107        let val = std::env::var($crate::conf::PRINT_STAT).unwrap_or("false".to_string());
108        if val.eq("true") {
109            println!("{}", format_args!($($arg)+));
110        }
111    }
112}
113
114// kdb 域(知识库)
115#[macro_export]
116macro_rules! trace_kdb { ($($arg:tt)+) => { $crate::re_exports::log::trace!(target: "kdb", $($arg)+) } }
117#[macro_export]
118macro_rules! debug_kdb { ($($arg:tt)+) => { $crate::re_exports::log::debug!(target: "kdb", $($arg)+) } }
119#[macro_export]
120macro_rules! info_kdb  { ($($arg:tt)+) => { $crate::re_exports::log::info!( target: "kdb", $($arg)+) } }
121#[macro_export]
122macro_rules! warn_kdb  { ($($arg:tt)+) => { $crate::re_exports::log::warn!( target: "kdb", $($arg)+) } }
123#[macro_export]
124macro_rules! error_kdb { ($($arg:tt)+) => { $crate::re_exports::log::error!(target: "kdb", $($arg)+) } }