library/runtime/log.zig wires std.log to the tagged ring: the root shim installs std_options for every binary (programs may override), logFn formats one line per record and emits it with its level via debug_write — the payload no longer carries the process's name; the kernel stamps identity structurally and the serial renderer prints the '<binary path>: ' prefix, so the transcript keeps its shape. Migrate every writeLine/logLine/log helper family (init, vfs, fat, device-manager, acpi, pci-bus, ps2-bus x3, usb-hid x2, usb-storage, usb-xhci-bus, virtio-gpu — 104 call sites) to std.log.info, dropping the hand-written prefixes. A leveled record is a complete line by contract (raw emissions may still build lines from pieces). Test fixtures and the display/input services keep raw writes for now — their ring records are attributed by the kernel regardless. Harness regexes follow the renamed prefixes (usb-hid-keyboard, discovery) and path-named restart lines.
52 lines
2.0 KiB
Zig
52 lines
2.0 KiB
Zig
//! The per-process logger: std.log wired to the tagged kernel log ring.
|
|
//!
|
|
//! A program just calls `std.log.info("mounted {s}", .{path})` (or a scoped
|
|
//! logger); this backend formats the line into a fixed buffer and emits ONE
|
|
//! `debug_write` record carrying the level. The kernel stamps the record with
|
|
//! the sender's pid and task name (its binary path) — the process does NOT put
|
|
//! its own name in the payload; attribution is the kernel's, structural and
|
|
//! unforgeable. Serial shows the kernel-rendered `<path>: message` line, and
|
|
//! the logger service demultiplexes the ring into one file per process.
|
|
//!
|
|
//! Installed for every user binary by the root shim (library/runtime/root.zig)
|
|
//! via `std_options`; a program can override by declaring its own
|
|
//! `pub const std_options`.
|
|
|
|
const std = @import("std");
|
|
const system = @import("system.zig");
|
|
|
|
fn levelOf(comptime level: std.log.Level) system.KlogLevel {
|
|
return switch (level) {
|
|
.err => .err,
|
|
.warn => .warn,
|
|
.info => .info,
|
|
.debug => .debug,
|
|
};
|
|
}
|
|
|
|
pub fn logFn(
|
|
comptime level: std.log.Level,
|
|
comptime scope: @EnumLiteral(),
|
|
comptime format: []const u8,
|
|
args: anytype,
|
|
) void {
|
|
// One record = one line = at most klog_maximum_message bytes of payload.
|
|
// On overflow keep what fits and end with "~" so the record is still a
|
|
// whole line (the kernel would split an embedded rest anyway).
|
|
var buffer: [256]u8 = undefined;
|
|
const prefix = if (scope == .default) "" else "(" ++ @tagName(scope) ++ ") ";
|
|
const line = std.fmt.bufPrint(&buffer, prefix ++ format, args) catch truncated: {
|
|
buffer[buffer.len - 1] = '~';
|
|
break :truncated buffer[0..];
|
|
};
|
|
_ = system.writeRecord(levelOf(level), line);
|
|
}
|
|
|
|
/// The std.Options the root shim installs unless the program overrides it.
|
|
/// Debug level: filtering is the log *reader's* job here — the ring is cheap,
|
|
/// serial is a dev convenience, and the logger service keeps everything.
|
|
pub const default_options: std.Options = .{
|
|
.log_level = .debug,
|
|
.logFn = logFn,
|
|
};
|