improving logger
Some checks failed
Build / build (push) Successful in 2m20s
Test / build_and_test (push) Failing after 1h21m19s

This commit is contained in:
2026-01-26 00:49:46 +01:00
parent b333f143b4
commit f042daa896
2 changed files with 68 additions and 55 deletions

View File

@@ -39,7 +39,7 @@ pub inline fn destroy(self: *Self, allocator: std.mem.Allocator) void {
fn logShaderModule(allocator: std.mem.Allocator, info: *const vk.ShaderModuleCreateInfo) !void { fn logShaderModule(allocator: std.mem.Allocator, info: *const vk.ShaderModuleCreateInfo) !void {
std.log.scoped(.ShaderModule).info("Logging SPIR-V module", .{}); std.log.scoped(.ShaderModule).info("Logging SPIR-V module", .{});
var process = std.process.Child.init(&[_][]const u8{ "spirv-dis", "--no-color", "/home/kbz8/Documents/Code/Zig/SPIRV-Interpreter/example/shader.spv" }, allocator); var process = std.process.Child.init(&[_][]const u8{ "spirv-dis", "/home/kbz_8/Documents/Code/Zig/SPIRV-Interpreter/example/shader.spv" }, allocator);
process.stdout_behavior = .Pipe; process.stdout_behavior = .Pipe;
process.stderr_behavior = .Pipe; process.stderr_behavior = .Pipe;
@@ -55,14 +55,17 @@ fn logShaderModule(allocator: std.mem.Allocator, info: *const vk.ShaderModuleCre
_ = process.kill() catch {}; _ = process.kill() catch {};
} }
if (process.stdin) |stdin| { _ = info;
_ = try stdin.write(@ptrCast(@alignCast(info.p_code[0..@divExact(info.code_size, 4)]))); //try process.collectOutput(allocator, &stdout, &stderr, 1024 * 1024);
} //if (process.stdin) |stdin| {
try process.collectOutput(allocator, &stdout, &stderr, 1024 * 1024); // _ = try stdin.write(@as([*]const u8, @ptrCast(info.p_code))[0..info.code_size]);
//} else {
// std.log.scoped(.ShaderModule).err("Failed to disassemble SPIR-V module to readable text.", .{});
//}
_ = try process.wait(); _ = try process.wait();
if (stderr.items.len != 0) { if (stderr.items.len != 0) {
std.log.scoped(.ShaderModule).err("Failed to disassemble SPIR-V module to readable text.\nError:\n{s}", .{stderr.items}); std.log.scoped(.ShaderModule).err("Failed to disassemble SPIR-V module to readable text.\n{s}", .{stderr.items});
} else if (stdout.items.len != 0) { } else if (stdout.items.len != 0) {
std.log.scoped(.ShaderModule).info("{s}\n{d}", .{ stdout.items, stdout.items.len }); std.log.scoped(.ShaderModule).info("{s}\n{d}", .{ stdout.items, stdout.items.len });
} }

View File

@@ -66,14 +66,21 @@ pub fn log(comptime level: std.log.Level, comptime scope: @Type(.enum_literal),
.warn, .err => stderr_file, .warn, .err => stderr_file,
}; };
var buffer = std.mem.zeroes([512]u8);
var out_config = std.Io.tty.Config.detect(file);
var writer = std.Io.Writer.fixed(&buffer);
var timezone = zdt.Timezone.tzLocal(std.heap.page_allocator) catch zdt.Timezone.UTC; var timezone = zdt.Timezone.tzLocal(std.heap.page_allocator) catch zdt.Timezone.UTC;
defer timezone.deinit(); defer timezone.deinit();
const now = zdt.Datetime.now(.{ .tz = &timezone }) catch zdt.Datetime{}; const now = zdt.Datetime.now(.{ .tz = &timezone }) catch zdt.Datetime{};
var fmt_buffer = std.mem.zeroes([4096]u8);
var fmt_writer = std.Io.Writer.fixed(&fmt_buffer);
fmt_writer.print(format ++ "\n", args) catch {};
fmt_writer.flush() catch return;
var last_pos: usize = 0;
while (std.mem.indexOfScalarPos(u8, &fmt_buffer, last_pos, '\n')) |pos| {
var buffer = std.mem.zeroes([512]u8);
var out_config = std.Io.tty.Config.detect(file);
var writer = std.Io.Writer.fixed(&buffer);
out_config.setColor(&writer, .magenta) catch {}; out_config.setColor(&writer, .magenta) catch {};
writer.print("[StrollDriver ", .{}) catch {}; writer.print("[StrollDriver ", .{}) catch {};
if (!builtin.is_test) { if (!builtin.is_test) {
@@ -102,7 +109,8 @@ pub fn log(comptime level: std.log.Level, comptime scope: @Type(.enum_literal),
writer.print("> ", .{}) catch {}; writer.print("> ", .{}) catch {};
} }
} }
writer.print(format ++ "\n", args) catch {};
writer.print("{s}\n", .{fmt_buffer[last_pos..pos]}) catch {};
writer.flush() catch return; writer.flush() catch return;
if (level == .debug and lib.getLogVerboseLevel() == .Standard) { if (level == .debug and lib.getLogVerboseLevel() == .Standard) {
@@ -127,4 +135,6 @@ pub fn log(comptime level: std.log.Level, comptime scope: @Type(.enum_literal),
.info, .debug => _ = stdout_file.write(&buffer) catch {}, .info, .debug => _ = stdout_file.write(&buffer) catch {},
.warn, .err => _ = stderr_file.write(&buffer) catch {}, .warn, .err => _ = stderr_file.write(&buffer) catch {},
} }
last_pos = pos + 1;
}
} }