Skip to content

Commit fbce4b1

Browse files
committed
Add timestamp to log
1 parent 02ca74b commit fbce4b1

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

src/main.zig

+12-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,18 @@ pub fn logHandler(
1919
args: anytype,
2020
) void {
2121
if (@intFromEnum(level) <= @intFromEnum(current_log_level)) {
22-
std.log.defaultLog(level, scope, format, args);
22+
const level_txt = comptime level.asText();
23+
const prefix2 = if (scope == .default) ": " else "(" ++ @tagName(scope) ++ "): ";
24+
const stderr = std.io.getStdErr().writer();
25+
var bw = std.io.bufferedWriter(stderr);
26+
const writer = bw.writer();
27+
28+
std.debug.lockStdErr();
29+
defer std.debug.unlockStdErr();
30+
nosuspend {
31+
writer.print("{d:.3} " ++ level_txt ++ prefix2 ++ format ++ "\n", .{@as(f64, @floatFromInt(std.time.milliTimestamp())) / 1000.0} ++ args) catch return;
32+
bw.flush() catch return;
33+
}
2334
}
2435
}
2536

0 commit comments

Comments
 (0)