jam_pvm_common/
logging.rs1#[cfg(any(feature = "logging", doc))]
2pub mod stuff {
3 #[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 #[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 #[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 #[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 #[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 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 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 #[macro_export]
78 macro_rules! error {
79 ($($arg:tt)*) => {
80 { let _ = ($( $arg, )*); }
81 };
82 }
83
84 #[macro_export]
86 macro_rules! warn {
87 ($($arg:tt)*) => {
88 { let _ = ($( $arg, )*); }
89 };
90 }
91
92 #[macro_export]
94 macro_rules! info {
95 ($($arg:tt)*) => {
96 { let _ = ($( $arg, )*); }
97 };
98 }
99
100 #[macro_export]
102 macro_rules! debug {
103 ($($arg:tt)*) => {
104 { let _ = ($( $arg, )*); }
105 };
106 }
107
108 #[macro_export]
110 macro_rules! trace {
111 ($($arg:tt)*) => {
112 { let _ = ($( $arg, )*); }
113 };
114 }
115}