jam_pvm_common/
logging.rs

1#[cfg(any(feature = "logging", doc))]
2pub mod stuff {
3	/// Log a message with the `error` level. Regular formatting may be used.
4	#[macro_export]
5	macro_rules! error {
6		(target=$target:expr,$($arg:tt)*) => {
7			$crate::logging::stuff::log_target(0, $target, &alloc::format!($($arg)*));
8		};
9		($($arg:tt)*) => {
10			$crate::logging::stuff::log(0, &alloc::format!($($arg)*));
11		};
12	}
13
14	/// Log a message with the `warn` level. Regular formatting may be used.
15	#[macro_export]
16	macro_rules! warn {
17		(target=$target:expr,$($arg:tt)*) => {
18			$crate::logging::stuff::log_target(1, $target, &alloc::format!($($arg)*));
19		};
20		($($arg:tt)*) => {
21			$crate::logging::stuff::log(1, &alloc::format!($($arg)*));
22		};
23	}
24
25	/// Log a message with the `info` level. Regular formatting may be used.
26	#[macro_export]
27	macro_rules! info {
28		(target=$target:expr,$($arg:tt)*) => {
29			$crate::logging::stuff::log_target(2, $target, &alloc::format!($($arg)*));
30		};
31		($($arg:tt)*) => {
32			$crate::logging::stuff::log(2, &alloc::format!($($arg)*));
33		};
34	}
35
36	/// Log a message with the `debug` level. Regular formatting may be used.
37	#[macro_export]
38	macro_rules! debug {
39		(target=$target:expr,$($arg:tt)*) => {
40			$crate::logging::stuff::log_target(3, $target, &alloc::format!($($arg)*));
41		};
42		($($arg:tt)*) => {
43			$crate::logging::stuff::log(3, &alloc::format!($($arg)*));
44		};
45	}
46
47	/// Log a message with the `trace` level. Regular formatting may be used.
48	#[macro_export]
49	macro_rules! trace {
50		(target=$target:expr,$($arg:tt)*) => {
51			$crate::logging::stuff::log_target(4, $target, &alloc::format!($($arg)*));
52		};
53		($($arg:tt)*) => {
54			$crate::logging::stuff::log(4, &alloc::format!($($arg)*));
55		};
56	}
57
58	// CAUTION: Not public API. DO NOT USE.
59	pub fn log_target(level: u64, target: &str, msg: &str) {
60		let t = target.as_bytes();
61		let m = msg.as_bytes();
62		unsafe {
63			crate::imports::log(level, t.as_ptr(), t.len() as u64, m.as_ptr(), m.len() as u64)
64		}
65	}
66
67	// CAUTION: Not public API. DO NOT USE.
68	pub fn log(level: u64, msg: &str) {
69		let m = msg.as_bytes();
70		unsafe { crate::imports::log(level, core::ptr::null(), 0u64, m.as_ptr(), m.len() as u64) }
71	}
72}
73
74#[cfg(not(any(feature = "logging", doc)))]
75pub mod stuff {
76	/// Log a message with the `error` level. Regular formatting may be used.mod stuff {
77	#[macro_export]
78	macro_rules! error {
79		($($arg:tt)*) => {
80			{ let _ = ($( $arg, )*); }
81		};
82	}
83
84	/// Log a message with the `warn` level. Regular formatting may be used.
85	#[macro_export]
86	macro_rules! warn {
87		($($arg:tt)*) => {
88			{ let _ = ($( $arg, )*); }
89		};
90	}
91
92	/// Log a message with the `info` level. Regular formatting may be used.
93	#[macro_export]
94	macro_rules! info {
95		($($arg:tt)*) => {
96			{ let _ = ($( $arg, )*); }
97		};
98	}
99
100	/// Log a message with the `debug` level. Regular formatting may be used.
101	#[macro_export]
102	macro_rules! debug {
103		($($arg:tt)*) => {
104			{ let _ = ($( $arg, )*); }
105		};
106	}
107
108	/// Log a message with the `trace` level. Regular formatting may be used.
109	#[macro_export]
110	macro_rules! trace {
111		($($arg:tt)*) => {
112			{ let _ = ($( $arg, )*); }
113		};
114	}
115}