|
1 | 1 | //! Logging macro implementations and other formating functions |
2 | 2 |
|
3 | | -/// Logs a trace message using the underlying logger |
4 | | -#[macro_export] |
5 | | -#[collapse_debuginfo(yes)] |
6 | | -macro_rules! trace { |
7 | | - ($s:literal $(, $x:expr)* $(,)?) => { |
8 | | - { |
9 | | - #[cfg(feature = "defmt")] |
10 | | - ::defmt::trace!($s $(, $x)*); |
11 | | - #[cfg(feature = "log")] |
12 | | - ::log::trace!($s $(, $x)*); |
13 | | - #[cfg(not(any(feature = "defmt", feature = "log")))] |
14 | | - let _ = ($( & $x ),*); |
15 | | - } |
16 | | - }; |
17 | | -} |
| 3 | +#[cfg(all(feature = "log", feature = "defmt", not(doc)))] |
| 4 | +compile_error!("features `log` and `defmt` are mutually exclusive"); |
18 | 5 |
|
19 | | -/// Logs a debug message using the underlying logger |
20 | | -#[macro_export] |
21 | | -#[collapse_debuginfo(yes)] |
22 | | -macro_rules! debug { |
23 | | - ($s:literal $(, $x:expr)* $(,)?) => { |
24 | | - { |
25 | | - #[cfg(feature = "defmt")] |
26 | | - ::defmt::debug!($s $(, $x)*); |
27 | | - #[cfg(feature = "log")] |
28 | | - ::log::debug!($s $(, $x)*); |
29 | | - #[cfg(not(any(feature = "defmt", feature = "log")))] |
30 | | - let _ = ($( & $x ),*); |
31 | | - } |
32 | | - }; |
33 | | -} |
| 6 | +#[cfg(all(not(doc), feature = "defmt"))] |
| 7 | +mod defmt { |
| 8 | + /// Logs a trace message using the underlying logger |
| 9 | + #[macro_export] |
| 10 | + #[collapse_debuginfo(yes)] |
| 11 | + macro_rules! trace { |
| 12 | + ($s:literal $(, $x:expr)* $(,)?) => { |
| 13 | + { |
| 14 | + ::defmt::trace!($s $(, $x)*); |
| 15 | + } |
| 16 | + }; |
| 17 | + } |
| 18 | + |
| 19 | + /// Logs a debug message using the underlying logger |
| 20 | + #[macro_export] |
| 21 | + #[collapse_debuginfo(yes)] |
| 22 | + macro_rules! debug { |
| 23 | + ($s:literal $(, $x:expr)* $(,)?) => { |
| 24 | + { |
| 25 | + ::defmt::debug!($s $(, $x)*); |
| 26 | + } |
| 27 | + }; |
| 28 | + } |
| 29 | + |
| 30 | + /// Logs an info message using the underlying logger |
| 31 | + #[macro_export] |
| 32 | + #[collapse_debuginfo(yes)] |
| 33 | + macro_rules! info { |
| 34 | + ($s:literal $(, $x:expr)* $(,)?) => { |
| 35 | + { |
| 36 | + ::defmt::info!($s $(, $x)*); |
| 37 | + } |
| 38 | + }; |
| 39 | + } |
34 | 40 |
|
35 | | -/// Logs a info message using the underlying logger |
36 | | -#[macro_export] |
37 | | -#[collapse_debuginfo(yes)] |
38 | | -macro_rules! info { |
39 | | - ($s:literal $(, $x:expr)* $(,)?) => { |
40 | | - { |
41 | | - #[cfg(feature = "defmt")] |
42 | | - ::defmt::info!($s $(, $x)*); |
43 | | - #[cfg(feature = "log")] |
44 | | - ::log::info!($s $(, $x)*); |
45 | | - #[cfg(not(any(feature = "defmt", feature = "log")))] |
46 | | - let _ = ($( & $x ),*); |
47 | | - } |
48 | | - }; |
| 41 | + /// Logs a warning using the underlying logger |
| 42 | + #[macro_export] |
| 43 | + #[collapse_debuginfo(yes)] |
| 44 | + macro_rules! warn { |
| 45 | + ($s:literal $(, $x:expr)* $(,)?) => { |
| 46 | + { |
| 47 | + ::defmt::warn!($s $(, $x)*); |
| 48 | + } |
| 49 | + }; |
| 50 | + } |
| 51 | + |
| 52 | + /// Logs an error using the underlying logger |
| 53 | + #[macro_export] |
| 54 | + #[collapse_debuginfo(yes)] |
| 55 | + macro_rules! error { |
| 56 | + ($s:literal $(, $x:expr)* $(,)?) => { |
| 57 | + { |
| 58 | + ::defmt::error!($s $(, $x)*); |
| 59 | + } |
| 60 | + }; |
| 61 | + } |
49 | 62 | } |
50 | 63 |
|
51 | | -/// Logs a warning using the underlying logger |
52 | | -#[macro_export] |
53 | | -#[collapse_debuginfo(yes)] |
54 | | -macro_rules! warn { |
55 | | - ($s:literal $(, $x:expr)* $(,)?) => { |
56 | | - { |
57 | | - #[cfg(feature = "defmt")] |
58 | | - ::defmt::warn!($s $(, $x)*); |
59 | | - #[cfg(feature = "log")] |
60 | | - ::log::warn!($s $(, $x)*); |
61 | | - #[cfg(not(any(feature = "defmt", feature = "log")))] |
62 | | - let _ = ($( & $x ),*); |
63 | | - } |
64 | | - }; |
| 64 | +#[cfg(all(not(doc), feature = "log"))] |
| 65 | +mod log { |
| 66 | + /// Logs a trace message using the underlying logger |
| 67 | + #[macro_export] |
| 68 | + #[collapse_debuginfo(yes)] |
| 69 | + macro_rules! trace { |
| 70 | + ($s:literal $(, $x:expr)* $(,)?) => { |
| 71 | + { |
| 72 | + ::log::trace!($s $(, $x)*); |
| 73 | + } |
| 74 | + }; |
| 75 | + } |
| 76 | + |
| 77 | + /// Logs a debug message using the underlying logger |
| 78 | + #[macro_export] |
| 79 | + #[collapse_debuginfo(yes)] |
| 80 | + macro_rules! debug { |
| 81 | + ($s:literal $(, $x:expr)* $(,)?) => { |
| 82 | + { |
| 83 | + ::log::debug!($s $(, $x)*); |
| 84 | + } |
| 85 | + }; |
| 86 | + } |
| 87 | + |
| 88 | + /// Logs an info message using the underlying logger |
| 89 | + #[macro_export] |
| 90 | + #[collapse_debuginfo(yes)] |
| 91 | + macro_rules! info { |
| 92 | + ($s:literal $(, $x:expr)* $(,)?) => { |
| 93 | + { |
| 94 | + ::log::info!($s $(, $x)*); |
| 95 | + } |
| 96 | + }; |
| 97 | + } |
| 98 | + |
| 99 | + /// Logs a warning using the underlying logger |
| 100 | + #[macro_export] |
| 101 | + #[collapse_debuginfo(yes)] |
| 102 | + macro_rules! warn { |
| 103 | + ($s:literal $(, $x:expr)* $(,)?) => { |
| 104 | + { |
| 105 | + ::log::warn!($s $(, $x)*); |
| 106 | + } |
| 107 | + }; |
| 108 | + } |
| 109 | + |
| 110 | + /// Logs an error using the underlying logger |
| 111 | + #[macro_export] |
| 112 | + #[collapse_debuginfo(yes)] |
| 113 | + macro_rules! error { |
| 114 | + ($s:literal $(, $x:expr)* $(,)?) => { |
| 115 | + { |
| 116 | + ::log::error!($s $(, $x)*); |
| 117 | + } |
| 118 | + }; |
| 119 | + } |
65 | 120 | } |
66 | 121 |
|
67 | | -/// Logs an error using the underlying logger |
68 | | -#[macro_export] |
69 | | -#[collapse_debuginfo(yes)] |
70 | | -macro_rules! error { |
71 | | - ($s:literal $(, $x:expr)* $(,)?) => { |
72 | | - { |
73 | | - #[cfg(feature = "defmt")] |
74 | | - ::defmt::error!($s $(, $x)*); |
75 | | - #[cfg(feature = "log")] |
76 | | - ::log::error!($s $(, $x)*); |
77 | | - #[cfg(not(any(feature = "defmt", feature = "log")))] |
78 | | - let _ = ($( & $x ),*); |
79 | | - } |
80 | | - }; |
| 122 | +// Provide this implementation for `cargo doc` |
| 123 | +#[cfg(any(doc, not(any(feature = "defmt", feature = "log"))))] |
| 124 | +mod none { |
| 125 | + /// Logs a trace message using the underlying logger |
| 126 | + #[macro_export] |
| 127 | + #[collapse_debuginfo(yes)] |
| 128 | + macro_rules! trace { |
| 129 | + ($s:literal $(, $x:expr)* $(,)?) => { |
| 130 | + { |
| 131 | + let _ = ($( & $x ),*); |
| 132 | + } |
| 133 | + }; |
| 134 | + } |
| 135 | + |
| 136 | + /// Logs a debug message using the underlying logger |
| 137 | + #[macro_export] |
| 138 | + #[collapse_debuginfo(yes)] |
| 139 | + macro_rules! debug { |
| 140 | + ($s:literal $(, $x:expr)* $(,)?) => { |
| 141 | + { |
| 142 | + let _ = ($( & $x ),*); |
| 143 | + } |
| 144 | + }; |
| 145 | + } |
| 146 | + |
| 147 | + /// Logs an info message using the underlying logger |
| 148 | + #[macro_export] |
| 149 | + #[collapse_debuginfo(yes)] |
| 150 | + macro_rules! info { |
| 151 | + ($s:literal $(, $x:expr)* $(,)?) => { |
| 152 | + { |
| 153 | + let _ = ($( & $x ),*); |
| 154 | + } |
| 155 | + }; |
| 156 | + } |
| 157 | + |
| 158 | + /// Logs a warning using the underlying logger |
| 159 | + #[macro_export] |
| 160 | + #[collapse_debuginfo(yes)] |
| 161 | + macro_rules! warn { |
| 162 | + ($s:literal $(, $x:expr)* $(,)?) => { |
| 163 | + { |
| 164 | + let _ = ($( & $x ),*); |
| 165 | + } |
| 166 | + }; |
| 167 | + } |
| 168 | + |
| 169 | + /// Logs an error using the underlying logger |
| 170 | + #[macro_export] |
| 171 | + #[collapse_debuginfo(yes)] |
| 172 | + macro_rules! error { |
| 173 | + ($s:literal $(, $x:expr)* $(,)?) => { |
| 174 | + { |
| 175 | + let _ = ($( & $x ),*); |
| 176 | + } |
| 177 | + }; |
| 178 | + } |
81 | 179 | } |
0 commit comments