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,65 +66,75 @@ 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{};
out_config.setColor(&writer, .magenta) catch {}; var fmt_buffer = std.mem.zeroes([4096]u8);
writer.print("[StrollDriver ", .{}) catch {}; var fmt_writer = std.Io.Writer.fixed(&fmt_buffer);
if (!builtin.is_test) { fmt_writer.print(format ++ "\n", args) catch {};
out_config.setColor(&writer, .cyan) catch {}; fmt_writer.flush() catch return;
writer.print(root.DRIVER_NAME, .{}) catch {};
}
out_config.setColor(&writer, .yellow) catch {};
writer.print(" {d:02}:{d:02}:{d:02}.{d:03}", .{ now.hour, now.minute, now.second, @divFloor(now.nanosecond, std.time.ns_per_ms) }) catch {};
out_config.setColor(&writer, .magenta) catch {};
writer.print("]", .{}) catch {};
out_config.setColor(&writer, level_color) catch {}; var last_pos: usize = 0;
writer.print(prefix, .{}) catch {}; 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, switch (level) { out_config.setColor(&writer, .magenta) catch {};
.err => .red, writer.print("[StrollDriver ", .{}) catch {};
.warn => .magenta, if (!builtin.is_test) {
else => .green, out_config.setColor(&writer, .cyan) catch {};
}) catch {}; writer.print(root.DRIVER_NAME, .{}) catch {};
writer.print("{s: >30}", .{scope_prefix}) catch {};
out_config.setColor(&writer, .reset) catch {};
if (getManager().get().indent_enabled) {
for (0..getManager().get().indent_level) |_| {
writer.print("> ", .{}) catch {};
} }
} out_config.setColor(&writer, .yellow) catch {};
writer.print(format ++ "\n", args) catch {}; writer.print(" {d:02}:{d:02}:{d:02}.{d:03}", .{ now.hour, now.minute, now.second, @divFloor(now.nanosecond, std.time.ns_per_ms) }) catch {};
writer.flush() catch return; out_config.setColor(&writer, .magenta) catch {};
writer.print("]", .{}) catch {};
if (level == .debug and lib.getLogVerboseLevel() == .Standard) { out_config.setColor(&writer, level_color) catch {};
getManager().get().debug_stack.pushBack(.{ writer.print(prefix, .{}) catch {};
.log = buffer,
.indent_level = getManager().get().indent_level,
.log_level = level,
}) catch return;
return;
}
if (getManager().get().indent_enabled) { out_config.setColor(&writer, switch (level) {
while (getManager().get().debug_stack.len() != 0) { .err => .red,
const elem = getManager().get().debug_stack.popFront(); .warn => .magenta,
switch (elem.log_level) { else => .green,
.info, .debug => _ = stdout_file.write(&elem.log) catch {}, }) catch {};
.warn, .err => _ = stderr_file.write(&elem.log) catch {}, writer.print("{s: >30}", .{scope_prefix}) catch {};
out_config.setColor(&writer, .reset) catch {};
if (getManager().get().indent_enabled) {
for (0..getManager().get().indent_level) |_| {
writer.print("> ", .{}) catch {};
} }
} }
}
switch (level) { writer.print("{s}\n", .{fmt_buffer[last_pos..pos]}) catch {};
.info, .debug => _ = stdout_file.write(&buffer) catch {}, writer.flush() catch return;
.warn, .err => _ = stderr_file.write(&buffer) catch {},
if (level == .debug and lib.getLogVerboseLevel() == .Standard) {
getManager().get().debug_stack.pushBack(.{
.log = buffer,
.indent_level = getManager().get().indent_level,
.log_level = level,
}) catch return;
return;
}
if (getManager().get().indent_enabled) {
while (getManager().get().debug_stack.len() != 0) {
const elem = getManager().get().debug_stack.popFront();
switch (elem.log_level) {
.info, .debug => _ = stdout_file.write(&elem.log) catch {},
.warn, .err => _ = stderr_file.write(&elem.log) catch {},
}
}
}
switch (level) {
.info, .debug => _ = stdout_file.write(&buffer) catch {},
.warn, .err => _ = stderr_file.write(&buffer) catch {},
}
last_pos = pos + 1;
} }
} }