mu_lib 0.2.2

XCENA mu Library
Documentation
//! Logger module providing logging functionality
//!
//! This module provides various log levels and logging output capabilities.

#![allow(non_upper_case_globals)]
#![allow(non_camel_case_types)]
#![allow(non_snake_case)]

pub use crate::bindings::root::mu::LogLevel_Critical as CLogLevel_Critical;
pub use crate::bindings::root::mu::LogLevel_Debug as CLogLevel_Debug;
pub use crate::bindings::root::mu::LogLevel_Error as CLogLevel_Error;
pub use crate::bindings::root::mu::LogLevel_Info as CLogLevel_Info;
pub use crate::bindings::root::mu::LogLevel_None as CLogLevel_None;
pub use crate::bindings::root::mu::LogLevel_Trace as CLogLevel_Trace;
pub use crate::bindings::root::mu::LogLevel_Warn as CLogLevel_Warn;
pub use crate::bindings::root::{logPrintfSingleStringRB, logPrintfWithLevelSingleStringRB};

pub use LogLevel as CLogLevel;

/// Enum defining log levels
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum LogLevel {
    /// Most detailed log level
    Trace = CLogLevel_Trace as isize,
    /// Debug log level
    Debug = CLogLevel_Debug as isize,
    /// General information log level
    Info = CLogLevel_Info as isize,
    /// Warning log level
    Warn = CLogLevel_Warn as isize,
    /// Error log level
    Error = CLogLevel_Error as isize,
    /// Critical error log level
    Critical = CLogLevel_Critical as isize,
    /// No logging
    None = CLogLevel_None as isize,
}

impl From<LogLevel> for i32 {
    fn from(level: LogLevel) -> Self {
        level as i32
    }
}

/// Macro for logging output
///
/// # Examples
/// ```
/// log_print!("This is a log message");
/// ```
#[macro_export]
macro_rules! log_print {
    ($($arg:tt)*) => {{
        let mut output = alloc::format!($($arg)*);
        output.push('\0');
        unsafe { $crate::logger::logPrintfSingleStringRB(output.as_ptr() as *const u8) }
    }};
}

/// Macro for logging output with a specified level
///
/// # Arguments
/// * `level` - The log level
///
/// # Examples
/// ```
/// log_print_with_level!(LogLevel::Info, "This is an info message");
/// ```
#[macro_export]
macro_rules! log_print_with_level {
    ($level:expr, $($arg:tt)*) => {{
        let mut output = alloc::format!($($arg)*);
        output.push('\0');
        unsafe { $crate::logger::logPrintfWithLevelSingleStringRB($level as i32, output.as_ptr() as *const u8) }
    }};
}