feat(zlog): colored level text and styled timestamps and scopes
All checks were successful
Zig Project Action / Lint, Spell-check and test zig project (push) Successful in 1m27s
All checks were successful
Zig Project Action / Lint, Spell-check and test zig project (push) Successful in 1m27s
This commit is contained in:
13
src/zlog.zig
13
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 {
|
||||
|
||||
Reference in New Issue
Block a user