Fix default error logfile

Don't use stderr for error logfile if primary logfile is not stdout
(i.e. always use the same file).

Fix non-colorized duration in DeveolpmentLogger - use std.fmt.fmtDurationSigned.
This commit is contained in:
Bob Farrell 2024-03-20 23:39:27 +00:00
parent 09bbcebb56
commit 054d1b5d82
2 changed files with 9 additions and 2 deletions

View File

@ -120,7 +120,10 @@ fn getLogFile(stream: enum { stdout, stderr }, options: Options) !std.fs.File {
if (std.mem.eql(u8, path, "-")) return switch (stream) {
.stdout => std.io.getStdOut(),
.stderr => std.io.getStdErr(),
.stderr => if (std.mem.eql(u8, options.log, "-"))
std.io.getStdErr()
else
try std.fs.createFileAbsolute(options.log, .{ .truncate = false }),
};
const file = try std.fs.createFileAbsolute(path, .{ .truncate = false });

View File

@ -68,7 +68,11 @@ pub fn logRequest(self: DevelopmentLogger, request: *const jetzig.http.Request)
const formatted_duration = if (self.stdout_colorized)
try jetzig.colors.duration(self.allocator, jetzig.util.duration(request.start_time))
else
try std.fmt.allocPrint(self.allocator, "{}", .{jetzig.util.duration(request.start_time)});
try std.fmt.allocPrint(
self.allocator,
"{}",
.{std.fmt.fmtDurationSigned(jetzig.util.duration(request.start_time))},
);
defer self.allocator.free(formatted_duration);
const status: jetzig.http.status_codes.TaggedStatusCode = switch (request.response.status_code) {