tail_core 0.1.0

Core library for the Tail operating system
Documentation
// Copyright 2025, TAIL OS. All Rights Reserved.
//
// You must obtain a written license from and pay applicable license fees to TAIL OS
// before you may reproduce, modify, or distribute this software, or any work that
// includes all or part of this software.
//
// Free development licenses are available for evaluation, research, and non-commercial
// purposes, which may include access to the source code under these terms. Redistribution
// or commercial use without a license is strictly prohibited.
//
// This file may contain contributions from others. Please review this entire file for
// other proprietary rights or license notices, as well as the TAIL OS License Guide at
// https://tail-os.com/license-guide/ for more information.
//
// For licensing inquiries, visit https://tail-os.com or email license@tail-os.com.


#![allow(dead_code)]

/// Log levels for klog!
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum LogLevel {
    /// Start of an operation or initialization
    Start,
    /// Successful completion of an operation
    Success,
    /// Error condition
    Error,
}

impl LogLevel {
    /// Get the string representation of the log level
    fn as_str(&self) -> &'static str {
        match self {
            LogLevel::Start => "START",
            LogLevel::Success => "SUCCESS",
            LogLevel::Error => "ERROR",
        }
    }
}

/// Log a message with a specific log level using kprint!
///
/// # Arguments
/// * `level` - The log level (START, SUCCESS, or ERROR)
/// * `message` - The message to log (supports format_args! syntax)
///
/// # Examples
/// ```
/// klog!(START, "aarch64-startup");
/// klog!(SUCCESS, "kprint!() is initialized");
/// klog!(ERROR, "Failed to initialize timer");
/// klog!(SUCCESS, "Initialized {} devices", count);
/// ```
#[macro_export]
macro_rules! klog {
    (START, $($args:tt)*) => {{
        #[allow(unused_imports)]
        {
            use tail_core::kprint::kprint;
            use tail_core::rich_text::*;
            kprint(format_args!("{}{}[START]{} ", BOLD, BLU, RESET));
            kprint(format_args!($($args)*));
            kprint(format_args!("\n"));
        }
    }};
    (SUCCESS, $($args:tt)*) => {{
        #[allow(unused_imports)]
        {
            use tail_core::kprint::kprint;
            use tail_core::rich_text::*;
            kprint(format_args!("{}{}[SUCCESS]{} ", BOLD, BLU, RESET));
            kprint(format_args!($($args)*));
            kprint(format_args!("\n"));
        }
    }};
    (ERROR, $($args:tt)*) => {{
        #[allow(unused_imports)]
        {
            use tail_core::kprint::kprint;
            use tail_core::rich_text::*;
            kprint(format_args!("{}{}[ERROR]{} ", BOLD, RED, RESET));
            kprint(format_args!($($args)*));
            kprint(format_args!("\n"));
        }
    }};
}

#[cfg(test)]
mod tests {
    use super::*;

    #[test]
    fn test_log_level_as_str() {
        assert_eq!(LogLevel::Start.as_str(), "START");
        assert_eq!(LogLevel::Success.as_str(), "SUCCESS");
        assert_eq!(LogLevel::Error.as_str(), "ERROR");
    }
}