Log now print always the same length

When printing 12:03 it was 12;3 before, now it's fix and use the
DateTime.format function
This commit is contained in:
Adrien Bouvais 2024-10-20 10:15:25 +02:00
parent 34688a0180
commit c7d7a01fa8
2 changed files with 6 additions and 4 deletions

View File

@ -135,7 +135,11 @@ pub const FileEngine = struct {
const now = DateTime.now();
// TODO: Use a format to add the 0 to be 00:00 and not 0:0
writer.print("Time: {d}/{d}/{d}-{d}:{d}:{d}.{d} - ", .{ now.years, now.months, now.days, now.hours, now.minutes, now.seconds, now.ms }) catch return;
var date_format_buffer = std.ArrayList(u8).init(self.allocator);
defer date_format_buffer.deinit();
now.format("YYYY/MM/DD-HH:mm:ss.SSSS", date_format_buffer.writer()) catch return;
writer.print("Time: {s} - ", .{date_format_buffer.items}) catch return;
switch (level) {
.Debug => writer.print("Debug - ", .{}) catch return,
.Info => writer.print("Info - ", .{}) catch return,

View File

@ -237,9 +237,7 @@ pub const DateTime = struct {
}
/// fmt is based on https://momentjs.com/docs/#/displaying/format/
pub fn format(self: Self, comptime fmt: string, options: std.fmt.FormatOptions, writer: anytype) !void {
_ = options;
pub fn format(self: Self, comptime fmt: string, writer: anytype) !void {
if (fmt.len == 0) @compileError("DateTime: format string can't be empty");
@setEvalBranchQuota(100000);