Skip to main content

Crate polished_serial_logging

Crate polished_serial_logging 

Source
Expand description

§Serial Logging Library for x86_64 Kernels

This crate provides robust serial port logging for kernel and bootloader environments, with a focus on QEMU usage. It offers macros and functions for formatted and raw serial output, as well as a minimal kprint! macro for early boot or no_std contexts where dependencies are limited.

§QEMU Serial Logging

QEMU can redirect the guest’s serial port (COM1, 0x3F8) to the host’s standard output or a file. This allows you to see kernel logs by running QEMU with -serial stdio or -serial file:output.log. All output sent to the serial port will appear in your terminal or the specified file, making debugging much easier, especially before graphics or higher-level logging is available.

§When to Use serial_log!/serial_print! vs kprint!

  • Use serial_log!, serial_print!, and related macros for most kernel logging. These use a full-featured serial driver (with buffering, formatting, and thread safety) and are suitable once the kernel is initialized.
  • Use kprint! for minimal, dependency-free output in very early boot stages, or in environments where only core formatting is available. kprint! writes directly to the serial port using inline assembly, bypassing all higher-level abstractions.

§Features

  • Thread-safe, formatted serial output via serial_print!, serial_log!, etc.
  • Log level macros for info, warning, and error messages.
  • Hexadecimal logging support.
  • Minimal kprint! macro for direct serial output.
  • Enable/disable logging at runtime.

§Example (QEMU):

qemu-system-x86_64 -serial stdio -kernel path/to/kernel

In your kernel code:

use polished_serial_logging::{serial_println, serial_log};

serial_println!("Hello, QEMU serial!");
serial_log!("[INFO] ", "Boot complete");

Re-exports§

pub use crate::kprint::DebugSerial;

Modules§

kprint

Macros§

error
Logs an error-level message to the serial port with formatting support.
kprint
Minimal serial debug output for kernel/boot environments.
serial_log
Logs a message to the serial port with a given log level prefix.
serial_log_hex
Logs a hexadecimal value to the serial port with a given log level prefix.
serial_print
Prints to the host through the serial interface (COM1, 0x3F8).
serial_println
Prints to the host through the serial interface, appending a newline.

Structs§

SERIAL1

Functions§

disable_serial_logging
Disables serial logging output.
enable_serial_logging
Enables serial logging output.
error
Logs an error-level message to the serial port.
info
Logs an info-level message to the serial port.
info_hex
Logs an info-level hexadecimal value to the serial port.
is_serial_logging_enabled
Returns whether serial logging is currently enabled.
serial_write_byte
Writes a single byte to the serial port (COM1, 0x3F8).
serial_write_hex
Writes a hexadecimal representation of a u64 value to the serial port.
serial_write_str
Writes a string to the serial port, byte by byte.
warn
Logs a warning-level message to the serial port.