diff options
| author | Nathan Reiner <nathan@nathanreiner.xyz> | 2026-10-05 19:38:16 +0200 |
|---|---|---|
| committer | Nathan Reiner <nathan@nathanreiner.xyz> | 2026-10-05 19:38:16 +0200 |
| commit | ec8ab44877368a1ac27dcdd615ad00bd1249407b (patch) | |
| tree | eb0578e4a7ffae77e4b352d8e5aa00ade68d9e24 /src/z/env | |
| parent | 5117cd94bdcc5b76ce4cb428b5ea47a6c5ab6ecf (diff) | |
add new method
Diffstat (limited to 'src/z/env')
| -rw-r--r-- | src/z/env/root.zig | 32 |
1 files changed, 32 insertions, 0 deletions
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); |