diff --git a/src/root.zig b/src/root.zig index 79d41d2..a62d801 100644 --- a/src/root.zig +++ b/src/root.zig @@ -18,17 +18,18 @@ fn logFn( }; const complete_format = level_txt ++ prefix ++ format ++ "\n"; var buf: [128]u8 = undefined; - if (comptime build_options.file.len != 0) { + 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) - const file = std.fs.openFileAbsolute(build_options.file, .{ - .mode = .read_write, - }) catch std.fs.createFileAbsolute(build_options.file, .{ - .truncate = false, - }) catch @panic("Failed to open and/or create configured log file"); - defer file.close(); + // file, err := os.OpenFile("log", os.O_APPEND|os.O_WRONLY|os.O_CREATE, 0600) + const fd = std.posix.open(build_options.file, .{ + .CREAT = true, + .APPEND = true, + .ACCMODE = .WRONLY, + }, 0o600) catch @panic("Could not append to log file"); + defer std.posix.close(fd); - var buffer = file.writer(&buf); + var buffer = std.fs.File.Writer.init(.{ .handle = fd }, &buf); var writer = &buffer.interface; defer writer.flush() catch {};