diff --git a/README.md b/README.md index 6b7e3b8..0250a78 100644 --- a/README.md +++ b/README.md @@ -143,11 +143,9 @@ This will result in the following output: For more details about the output customization see the configuration options of the `zlog` module. Following options are available: -- _timestamp_ (default: `true`): Prepend the current timestamp before each log message. -- _stderr_ (default: `true`): Print log messages to stderr. - > [!caution] - > Currently not working as log output is not appended and only the last log message will be in the resulting log file! This is a not-yet-implemented feature of the standard library of zig! See this [issue](https://github.com/ziglang/zig/issues/14375) for more details. - > For now you should instead leave this option as it is and pipe the corresponding stderr outputs to a logfile instead. +- *timestamp* (default: `true`): Prepend the current timestamp before each log message. +- *stderr* (default: `true`): Print log messages to stderr. +- *file* (default: `""`): File path to log messages to. Without a path no log file will be created and logged to. Can be used in parallel with the *stderr* option ## Tips diff --git a/src/root.zig b/src/root.zig index 4f8ba01..432612a 100644 --- a/src/root.zig +++ b/src/root.zig @@ -5,22 +5,20 @@ fn logFn( comptime format: []const u8, args: anytype, ) void { - // 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 prefix = if (scope == .default) ": " else "(\x1b[2m" ++ @tagName(scope) ++ "\x1b[0m): "; + // TODO this should only happen for messages that are written to *stderr* in files the escape codes are only annoying 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]", }; + // TODO let user configure the format he wants to use for logging and use a pretty good default one? const complete_format = level_txt ++ prefix ++ format ++ "\n"; var buf: [128]u8 = undefined; if (comptime build_options.file.len > 0) { - // TODO handle errors accordingly (i.e. panic?) - // NOTE with zig 0.13.0 there is currently no way to open files to append (except to use libc or talk directly to posix, which this lib should not have to do) + // TODO use common logging format, such that in integrates well with other logging frameworks + // (i.e. golang's logger, log4j, etc.) const fd = std.posix.open(build_options.file, .{ .CREAT = true, .APPEND = true,