Skip to main content

uika_runtime/
logging.rs

1// Logging bridge to UE_LOG.
2
3/// Log level constants for the `ulog!` macro.
4pub const LOG_DISPLAY: u8 = 0;
5pub const LOG_WARNING: u8 = 1;
6pub const LOG_ERROR: u8 = 2;
7
8/// Log a message through UE_LOG.
9///
10/// Usage:
11/// ```ignore
12/// ulog!(LOG_DISPLAY, "Actor {} has {} health", name, hp);
13/// ulog!(LOG_WARNING, "something suspicious");
14/// ulog!(LOG_ERROR, "fatal: {err}");
15/// ```
16///
17/// Level constants: `LOG_DISPLAY` (0), `LOG_WARNING` (1), `LOG_ERROR` (2).
18#[macro_export]
19macro_rules! ulog {
20    ($level:expr, $($arg:tt)*) => {{
21        let msg = format!($($arg)*);
22        let bytes = msg.as_bytes();
23        // SAFETY: api() is initialized before any Rust code can run, and the
24        // logging sub-table pointer is always valid after init.
25        unsafe {
26            ((*$crate::api().logging).log)($level, bytes.as_ptr(), bytes.len() as u32);
27        }
28    }};
29}