|
1 | 1 | const std = @import("std"); |
2 | 2 |
|
3 | | -var stdout_buf: [64]u8 = undefined; |
4 | | -var stdout_writer = std.fs.File.stdout().writer(&stdout_buf); |
5 | | -const stdout = &stdout_writer.interface; |
6 | | - |
7 | | -var stderr_buf: [64]u8 = undefined; |
8 | | -var stderr_writer = std.fs.File.stderr().writer(&stderr_buf); |
9 | | -const stderr = &stderr_writer.interface; |
10 | | - |
11 | 3 | pub fn query(comptime message: []const u8, args: anytype) void { |
12 | | - stdout.print("[?] " ++ message, args) catch {}; |
13 | | - stdout.flush() catch {}; |
| 4 | + printToStdout("[?] " ++ message, args); |
14 | 5 | } |
15 | 6 |
|
16 | 7 | pub fn log_stderr(comptime message: []const u8, args: anytype) void { |
17 | | - stderr.print("[l] " ++ message ++ "\n", args) catch {}; |
18 | | - stderr.flush() catch {}; |
| 8 | + printToStderr("[l] " ++ message ++ "\n", args); |
19 | 9 | } |
20 | 10 |
|
21 | 11 | pub fn info(comptime message: []const u8, args: anytype) void { |
22 | | - stdout.print("[i] " ++ message ++ "\n", args) catch {}; |
23 | | - stdout.flush() catch {}; |
| 12 | + printToStdout("[i] " ++ message ++ "\n", args); |
24 | 13 | } |
25 | 14 |
|
26 | 15 | pub fn warn(comptime message: []const u8, args: anytype) void { |
27 | | - stderr.print("[w] " ++ message ++ "\n", args) catch {}; |
28 | | - stderr.flush() catch {}; |
| 16 | + printToStderr("[w] " ++ message ++ "\n", args); |
29 | 17 | } |
30 | 18 |
|
31 | 19 | pub fn err(comptime message: []const u8, args: anytype) void { |
32 | | - stderr.print("[!] " ++ message ++ "\n", args) catch {}; |
33 | | - stderr.flush() catch {}; |
| 20 | + printToStderr("[!] " ++ message ++ "\n", args); |
34 | 21 | } |
35 | 22 |
|
36 | 23 | pub fn crit(comptime message: []const u8, args: anytype) void { |
37 | | - stderr.print("[!!] " ++ message ++ "\n", args) catch {}; |
| 24 | + printToStderr("[!!] " ++ message ++ "\n", args); |
| 25 | +} |
| 26 | + |
| 27 | +fn printToStdout(comptime message: []const u8, args: anytype) void { |
| 28 | + var stdout_buf: [64]u8 = undefined; |
| 29 | + var stdout_writer = std.fs.File.stdout().writer(&stdout_buf); |
| 30 | + const stdout = &stdout_writer.interface; |
| 31 | + |
| 32 | + stdout.print(message, args) catch {}; |
| 33 | + stdout.flush() catch {}; |
| 34 | +} |
| 35 | + |
| 36 | +fn printToStderr(comptime message: []const u8, args: anytype) void { |
| 37 | + var stderr_buf: [64]u8 = undefined; |
| 38 | + var stderr_writer = std.fs.File.stderr().writer(&stderr_buf); |
| 39 | + const stderr = &stderr_writer.interface; |
| 40 | + |
| 41 | + stderr.print(message, args) catch {}; |
38 | 42 | stderr.flush() catch {}; |
39 | 43 | } |
0 commit comments