mirror of
https://codeberg.org/fairyglade/ly.git
synced 2026-08-24 06:24:20 +02:00
Add time, severity & category in logs
Signed-off-by: AnErrupTion <anerruption@disroot.org>
This commit is contained in:
parent
0c12008327
commit
2e04ea4d79
5 changed files with 95 additions and 83 deletions
|
|
@ -1,4 +1,5 @@
|
|||
const std = @import("std");
|
||||
const interop = @import("interop.zig");
|
||||
|
||||
const LogFile = @This();
|
||||
|
||||
|
|
@ -19,10 +20,29 @@ pub fn reinit(self: *LogFile) !void {
|
|||
}
|
||||
|
||||
pub fn deinit(self: *LogFile) void {
|
||||
self.file_writer.interface.flush() catch {};
|
||||
self.file.close();
|
||||
}
|
||||
|
||||
pub fn info(self: *LogFile, category: []const u8, comptime message: []const u8, args: anytype) !void {
|
||||
var buffer: [128:0]u8 = undefined;
|
||||
const time = interop.timeAsString(&buffer, "%Y-%m-%d %H:%M:%S");
|
||||
|
||||
try self.file_writer.interface.print("{s} [info/{s}] ", .{ time, category });
|
||||
try self.file_writer.interface.print(message, args);
|
||||
try self.file_writer.interface.writeByte('\n');
|
||||
try self.file_writer.interface.flush();
|
||||
}
|
||||
|
||||
pub fn err(self: *LogFile, category: []const u8, comptime message: []const u8, args: anytype) !void {
|
||||
var buffer: [128:0]u8 = undefined;
|
||||
const time = interop.timeAsString(&buffer, "%Y-%m-%d %H:%M:%S");
|
||||
|
||||
try self.file_writer.interface.print("{s} [err/{s}] ", .{ time, category });
|
||||
try self.file_writer.interface.print(message, args);
|
||||
try self.file_writer.interface.writeByte('\n');
|
||||
try self.file_writer.interface.flush();
|
||||
}
|
||||
|
||||
fn openLogFile(path: []const u8, log_file: *LogFile) !bool {
|
||||
var could_open_log_file = true;
|
||||
open_log_file: {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue