jam_pvm_common/
logging.rs

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

	/// Log a message with the `warn` level. Regular formatting may be used.
	#[macro_export]
	macro_rules! warn {
		(target=$target:expr,$($arg:tt)*) => {
			$crate::logging::stuff::log_target(1, $target, &alloc::format!($($arg)*));
		};
		($($arg:tt)*) => {
			$crate::logging::stuff::log(1, &alloc::format!($($arg)*));
		};
	}

	/// Log a message with the `info` level. Regular formatting may be used.
	#[macro_export]
	macro_rules! info {
		(target=$target:expr,$($arg:tt)*) => {
			$crate::logging::stuff::log_target(2, $target, &alloc::format!($($arg)*));
		};
		($($arg:tt)*) => {
			$crate::logging::stuff::log(2, &alloc::format!($($arg)*));
		};
	}

	/// Log a message with the `debug` level. Regular formatting may be used.
	#[macro_export]
	macro_rules! debug {
		(target=$target:expr,$($arg:tt)*) => {
			$crate::logging::stuff::log_target(3, $target, &alloc::format!($($arg)*));
		};
		($($arg:tt)*) => {
			$crate::logging::stuff::log(3, &alloc::format!($($arg)*));
		};
	}

	/// Log a message with the `trace` level. Regular formatting may be used.
	#[macro_export]
	macro_rules! trace {
		(target=$target:expr,$($arg:tt)*) => {
			$crate::logging::stuff::log_target(4, $target, &alloc::format!($($arg)*));
		};
		($($arg:tt)*) => {
			$crate::logging::stuff::log(4, &alloc::format!($($arg)*));
		};
	}

	// CAUTION: Not public API. DO NOT USE.
	pub fn log_target(level: u64, target: &str, msg: &str) {
		let t = target.as_bytes();
		let m = msg.as_bytes();
		unsafe {
			crate::imports::log(level, t.as_ptr(), t.len() as u64, m.as_ptr(), m.len() as u64)
		}
	}

	// CAUTION: Not public API. DO NOT USE.
	pub fn log(level: u64, msg: &str) {
		let m = msg.as_bytes();
		unsafe { crate::imports::log(level, core::ptr::null(), 0u64, m.as_ptr(), m.len() as u64) }
	}
}

#[cfg(not(any(feature = "logging", doc)))]
pub mod stuff {
	/// Log a message with the `error` level. Regular formatting may be used.mod stuff {
	#[macro_export]
	macro_rules! error {
		($($arg:tt)*) => {
			{ let _ = ($( $arg, )*); }
		};
	}

	/// Log a message with the `warn` level. Regular formatting may be used.
	#[macro_export]
	macro_rules! warn {
		($($arg:tt)*) => {
			{ let _ = ($( $arg, )*); }
		};
	}

	/// Log a message with the `info` level. Regular formatting may be used.
	#[macro_export]
	macro_rules! info {
		($($arg:tt)*) => {
			{ let _ = ($( $arg, )*); }
		};
	}

	/// Log a message with the `debug` level. Regular formatting may be used.
	#[macro_export]
	macro_rules! debug {
		($($arg:tt)*) => {
			{ let _ = ($( $arg, )*); }
		};
	}

	/// Log a message with the `trace` level. Regular formatting may be used.
	#[macro_export]
	macro_rules! trace {
		($($arg:tt)*) => {
			{ let _ = ($( $arg, )*); }
		};
	}
}