//! Module implementing the `print!`/`println!` macro.

/// Log an debug info
#[macro_export]
macro_rules! debug {
    ($string:expr) => ({
        use $crate::traits::time::TimeManager;
        let timestamp = $crate::time_manager().uptime();
        $crate::print::_print(format_args_nl!(
            concat!("[{:>6}.{:06}] DEBUG: ", $string),
            timestamp.as_secs(),
            timestamp.subsec_micros(),
        ));
    });
    ($format_string:expr, $($arg:tt)*) => ({
        use $crate::traits::time::TimeManager;
        let timestamp = $crate::time_manager().uptime();
        $crate::print::_print(format_args_nl!(
            concat!("[{:>6}.{:06}] DEBUG: ", $format_string),
            timestamp.as_secs(),
            timestamp.subsec_micros(),
            $($arg)*
        ));
    })
}

/// Log an info
#[macro_export]
macro_rules! info {
    ($string:expr) => ({
        use $crate::traits::time::TimeManager;
        let timestamp = $crate::time_manager().uptime();
        $crate::print::_print(format_args_nl!(
            concat!("[{:>6}.{:06}]  INFO: ", $string),
            timestamp.as_secs(),
            timestamp.subsec_micros(),
        ));
    });
    ($format_string:expr, $($arg:tt)*) => ({
        use $crate::traits::time::TimeManager;
        let timestamp = $crate::time_manager().uptime();
        $crate::print::_print(format_args_nl!(
            concat!("[{:>6}.{:06}]  INFO: ", $format_string),
            timestamp.as_secs(),
            timestamp.subsec_micros(),
            $($arg)*
        ));
    })
}

/// Log an warning
#[macro_export]
macro_rules! warn {
    ($string:expr) => ({
        use $crate::traits::time::TimeManager;
        let timestamp = $crate::time_manager().uptime();
        $crate::print::_print(format_args_nl!(
            concat!("[{:>6}.{:06}]  WARN: ", $string),
            timestamp.as_secs(),
            timestamp.subsec_micros(),
        ));
    });
    ($format_string:expr, $($arg:tt)*) => ({
        use $crate::traits::time::TimeManager;
        let timestamp = $crate::time_manager().uptime();
        $crate::print::_print(format_args_nl!(
            concat!("[{:>6}.{:06}]  WARN: ", $format_string),
            timestamp.as_secs(),
            timestamp.subsec_micros(),
            $($arg)*
        ));
    })
}

/// Log an error
#[macro_export]
macro_rules! error {
    ($string:expr) => ({
        use $crate::traits::time::TimeManager;
        let timestamp = $crate::time_manager().uptime();
        $crate::print::_print(format_args_nl!(
            concat!("[{:>6}.{:06}]   ERR: ", $string),
            timestamp.as_secs(),
            timestamp.subsec_micros(),
        ));
    });
    ($format_string:expr, $($arg:tt)*) => ({
        use $crate::traits::time::TimeManager;
        let timestamp = $crate::time_manager().uptime();
        $crate::print::_print(format_args_nl!(
            concat!("[{:>6}.{:06}]   ERR: ", $format_string),
            timestamp.as_secs(),
            timestamp.subsec_micros(),
            $($arg)*
        ));
    })
}

/// Log a fatal error
#[macro_export]
macro_rules! fatal {
    ($string:expr) => ({
        use $crate::traits::time::TimeManager;
        let timestamp = $crate::time_manager().uptime();
        $crate::print::_print(format_args_nl!(
            concat!("[{:>6}.{:06}] FATAL: ", $string),
            timestamp.as_secs(),
            timestamp.subsec_micros(),
        ));
    });
    ($format_string:expr, $($arg:tt)*) => ({
        use $crate::traits::time::TimeManager;
        let timestamp = $crate::time_manager().uptime();
        $crate::print::_print(format_args_nl!(
            concat!("[{:>6}.{:06}] FATAL: ", $format_string),
            timestamp.as_secs(),
            timestamp.subsec_micros(),
            $($arg)*
        ));
    })
}
