diff --git a/README.md b/README.md index e9a6ff8..fb65549 100644 --- a/README.md +++ b/README.md @@ -66,24 +66,24 @@ pub fn main() void { This will result in the following output: ``` -[2024-08-28 22:22] debug(main): Debug message 42 -[2024-08-28 22:22] info(main): Info message { 1, 2, 3, 4 } -[2024-08-28 22:22] info(main): Info message "This is a test" -[2024-08-28 22:22] warning(main): Warning message main.Options = enum { +[2025-02-24 13:00:08] [debug](main): Debug message 42 +[2025-02-24 13:00:08] [info](main): Info message { 1, 2, 3, 4 } +[2025-02-24 13:00:08] [info](main): Info message "This is a test" +[2025-02-24 13:00:08] [warning](main): Warning message main.Options = enum { + a, + b, + c, +} = a +[2025-02-24 13:00:08] [error](main): Error message main.Struct = struct { + .a = 42, + .b = true, + .c = []u16: { 1, 2, 3, 4, 5 }, + .d = { 115, 116, 114, 105, 110, 103 }, + .e = main.Options = enum { a, b, c, -} = a -[2024-08-28 22:22] error(main): Error message main.Struct = struct { - .a = 42, - .b = true, - .c = []u16: { 1, 2, 3, 4, 5 }, - .d = { 115, 116, 114, 105, 110, 103 }, - .e = main.Options = enum { - a, - b, - c, - } = b, + } = b, } ``` diff --git a/src/zlog.zig b/src/zlog.zig index aef6eab..e63485b 100644 --- a/src/zlog.zig +++ b/src/zlog.zig @@ -16,8 +16,15 @@ fn logFn( // TODO: provide build time configuration to allow tweaking corresponding output // - change output file for writing messages to (default `stderr`) // write into own file for each level? - const level_txt = comptime message_level.asText(); - const prefix = if (scope == .default) ": " else "(" ++ @tagName(scope) ++ "): "; + + // TODO: make the level text colored according to the level! + const prefix = if (scope == .default) ": " else "(\x1b[2m" ++ @tagName(scope) ++ "\x1b[0m): "; + const level_txt = switch (comptime message_level) { + .err => "[\x1b[38;5;9merror\x1b[0m]", + .warn => "[\x1b[38;5;11mwarning\x1b[0m]", + .info => "[\x1b[38;5;10minfo\x1b[0m]", + .debug => "[\x1b[38;5;12mdebug\x1b[0m]", + }; const fmt = level_txt ++ prefix ++ format ++ "\n"; if (comptime build_options.file.len != 0) { // TODO: handle errors accordingly (i.e. panic?) @@ -56,7 +63,7 @@ inline fn log_writing(writer: anytype, comptime fmt: []const u8, args: anytype) } inline fn log_timestamp(writer: anytype) void { - writer.print("[{any}] ", .{ztime.DateTime.now()}) catch return; + writer.print("[\x1b[1m{any}\x1b[0m] ", .{ztime.DateTime.now()}) catch return; } pub fn pretty_format(object: anytype, comptime fmt: []const u8, options: std.fmt.FormatOptions, writer: anytype) !void {