From ec8ab44877368a1ac27dcdd615ad00bd1249407b Mon Sep 17 00:00:00 2001 From: Nathan Reiner Date: Mon, 5 Oct 2026 19:38:16 +0200 Subject: add new method --- src/z/env/root.zig | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) (limited to 'src/z/env') diff --git a/src/z/env/root.zig b/src/z/env/root.zig index 9e49181..3ceac84 100644 --- a/src/z/env/root.zig +++ b/src/z/env/root.zig @@ -1,2 +1,34 @@ +const std = @import("std"); pub const console = @import("console.zig"); + +pub fn logFn( + comptime level: std.log.Level, + comptime scope: @EnumLiteral(), + comptime format: []const u8, + args: anytype, +) void { + var buffer: [1024]u8 = undefined; + var writer: std.Io.Writer = .fixed(&buffer); + + const func = switch (level) { + .err => console.err, + .warn => console.warn, + .info => console.log, + .debug => console.debug, + }; + + if (scope != .default) { + writer.print("[{s}]: ", .{@tagName(scope)}) catch unreachable; + } + writer.print(format, args) catch unreachable; + + func(writer.buffered()); +} + +fn defaultPanic(msg: []const u8, _: ?usize) noreturn { + console.err(msg); + @trap(); +} + +pub const panic = std.debug.FullPanic(defaultPanic); -- cgit v1.2.3-70-g09d2