improving logger
This commit is contained in:
@@ -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 {
|
||||
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.stderr_behavior = .Pipe;
|
||||
@@ -55,14 +55,17 @@ fn logShaderModule(allocator: std.mem.Allocator, info: *const vk.ShaderModuleCre
|
||||
_ = process.kill() catch {};
|
||||
}
|
||||
|
||||
if (process.stdin) |stdin| {
|
||||
_ = try stdin.write(@ptrCast(@alignCast(info.p_code[0..@divExact(info.code_size, 4)])));
|
||||
}
|
||||
try process.collectOutput(allocator, &stdout, &stderr, 1024 * 1024);
|
||||
_ = info;
|
||||
//try process.collectOutput(allocator, &stdout, &stderr, 1024 * 1024);
|
||||
//if (process.stdin) |stdin| {
|
||||
// _ = 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();
|
||||
|
||||
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) {
|
||||
std.log.scoped(.ShaderModule).info("{s}\n{d}", .{ stdout.items, stdout.items.len });
|
||||
}
|
||||
|
||||
@@ -66,14 +66,21 @@ pub fn log(comptime level: std.log.Level, comptime scope: @Type(.enum_literal),
|
||||
.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;
|
||||
defer timezone.deinit();
|
||||
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 {};
|
||||
writer.print("[StrollDriver ", .{}) catch {};
|
||||
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(format ++ "\n", args) catch {};
|
||||
|
||||
writer.print("{s}\n", .{fmt_buffer[last_pos..pos]}) catch {};
|
||||
writer.flush() catch return;
|
||||
|
||||
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 {},
|
||||
.warn, .err => _ = stderr_file.write(&buffer) catch {},
|
||||
}
|
||||
last_pos = pos + 1;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user