pub fn sys_log(tag: &str, log_type: u8, to_print: &str)Expand description
Core logging function that outputs formatted log messages.
This is the low-level function called by all log macros. It handles:
- Thread-safe output using a busy-wait lock
- Color formatting based on log level
- Timestamp prefixing with millisecond precision
- Tag prefixing for message categorization
§Parameters
tag- Category or module name for the log message (e.g., “APP”, “NET”, “FS”)log_type- Log level flag (DEBUG, INFO, WARNING, ERROR, FATAL)to_print- The formatted message string to log
§Thread Safety
Uses a busy-wait lock (BUSY flag) to ensure only one thread logs at a time:
- Spins until BUSY == 0
- Sets BUSY = 1
- Formats and outputs the message
- Sets BUSY = 0
Other threads will spin-wait during this time.
§Output Format
In no_std mode:
{color}({timestamp}ms)[{tag}] {message}{color_reset}\r\nExample:
\x1b[32m(1234ms)[APP] System initialized\x1b[0m\r\n§Examples
ⓘ
use osal_rs::log::*;
sys_log("APP", log_levels::FLAG_INFO, "Application started");
sys_log("NET", log_levels::FLAG_ERROR, "Connection failed");§Note
Prefer using the log macros (log_info!, log_error!, etc.) instead of
calling this function directly. The macros check if the log level is enabled
before formatting the message, avoiding allocation for disabled levels.
§Warning
Never call from ISR context - the busy-wait can cause deadlock if a higher-priority ISR preempts a task that holds the lock.