Skip to main content
The kernel log is a 16 KiB circular ring buffer that stores structured, timestamped log entries. Each entry carries a severity level string and an optional category tag alongside the message text. When the buffer is full, the oldest entries are overwritten so that the most recent activity is always available. You can mirror log output to the VGA console at any time, and you can snapshot the current buffer contents into your own memory for further processing.
The ring buffer has a fixed capacity of 16 KiB. When it is full, the oldest entries are silently overwritten. If you need a persistent log, copy the buffer to stable storage with klog_copy before it wraps.

Suggested Level Strings

The kernel log API accepts arbitrary level strings, but the following values are used by convention throughout MVH Kernel itself:

Functions

klog_init

Initialise the kernel log ring buffer. You must call this function exactly once during kernel startup, before calling any other log API function. Calling it a second time resets the ring and discards all existing log data.

klog_write

Write a log entry with a level and message. Use this function when you do not need a category tag.
const char *
required
A null-terminated severity string such as "INFO", "WARN", "ERROR", or "DEBUG". The string is copied into the entry, so you do not need to keep the pointer alive after the call.
const char *
required
A null-terminated log message. The message is copied into the ring buffer along with the level and a kernel-generated timestamp.

klog_write_category

Write a log entry with a level, an optional category tag, and a message. This is the preferred form when you want to associate entries with a named subsystem (for example "ACPI", "PCI", "VMM").
const char *
required
A null-terminated severity string. See klog_write for suggested values.
const char *
required
A null-terminated subsystem or component name. The dmesg shell command can filter by category, so choosing consistent category names makes log inspection easier.
const char *
required
A null-terminated log message.

klog_set_console

Control whether new log entries are mirrored to the VGA text console in real time. Console mirroring is disabled by default; enable it early in the boot sequence if you want live log output on screen.
uint8_t
required
Pass 1 to enable VGA console mirroring, or 0 to disable it. This setting affects only entries written after the call — it does not replay previously buffered entries.

klog_copy

Copy the current contents of the ring buffer into a caller-supplied byte buffer. The copy is a linear snapshot of all data currently in the ring, oldest entry first.
char *
required
Pointer to a buffer that will receive the log data. The buffer must be at least capacity bytes long. The copied data is not null-terminated automatically — add a null terminator yourself if you intend to treat the result as a C string.
uint32_t
required
The maximum number of bytes to copy. To guarantee a complete snapshot, pass a value of at least 16 384 (16 KiB).
uint32_t
The number of bytes written to output. This is min(klog_size(), capacity).

klog_size

Return the number of bytes of log data currently stored in the ring buffer.
uint32_t
The current occupancy of the ring buffer in bytes, in the range [0, 16384].

Shell Command

The built-in dmesg shell command dumps the full contents of the kernel log ring buffer to the console:

Example

The following example initialises the log, writes several categorised entries at different severity levels, then takes a snapshot of the entire ring for further inspection.