Ability to turn off logging #1212

Open
opened 2024-06-06 02:07:53 +00:00 by ghost · 1 comment
ghost commented 2024-06-06 02:07:53 +00:00 (Migrated from github.com)

Would be nice if I could turn off logging to the terminal. I always get two lines and a newline about it failing to "CreateInstance in ICD 1" and it having found the Vulkan backend.
Everything works fine so I would like to just turn off logging but I'm not sure how to do so.
As for any error it'd be nice if it returned an error union instead of printing something to the console so I can handle it. Currently it's using log.err followed by a std.process.exit(1) in a bunch of places and I'm not sure that's the best it can do. Maybe I don't want to have my process exited when Mach failed to initialize.

Would be nice if I could turn off logging to the terminal. I always get two lines and a newline about it failing to "CreateInstance in ICD 1" and it having found the Vulkan backend. Everything works fine so I would like to just turn off logging but I'm not sure how to do so. As for any error it'd be nice if it returned an error union instead of printing something to the console so I can handle it. Currently it's using `log.err` followed by a `std.process.exit(1)` in a bunch of places and I'm not sure that's the best it can do. Maybe I don't want to have my process exited when Mach failed to initialize.
pfgithub commented 2024-06-14 16:37:34 +00:00 (Migrated from github.com)

The log is scoped to '.mach', so it can be turned off by using a custom log function (zig std.Options.log_scope_levels doesn't seem to be able to turn off logging for a specific scope, only set it to errors only?). Although there seem to be some unscoped logs in the library and those can't be turned off: https://github.com/search?q=repo%3Ahexops%2Fmach%20log.err&type=code

pub const std_options: std.Options = .{
    .log_fn = logFn,
};
fn logFn(
    comptime message_level: Level,
    comptime scope: @Type(.EnumLiteral),
    comptime format: []const u8,
    args: anytype,
) void {
    if(scope == .mach) return;
    return std.log.defaultLog(message_level, scope, format, args);
}

std.process.exit is a problem.

The log is scoped to '.mach', so it can be turned off by using a custom log function (zig std.Options.log_scope_levels doesn't seem to be able to turn off logging for a specific scope, only set it to errors only?). Although there seem to be some unscoped logs in the library and those can't be turned off: https://github.com/search?q=repo%3Ahexops%2Fmach%20log.err&type=code ```zig pub const std_options: std.Options = .{ .log_fn = logFn, }; fn logFn( comptime message_level: Level, comptime scope: @Type(.EnumLiteral), comptime format: []const u8, args: anytype, ) void { if(scope == .mach) return; return std.log.defaultLog(message_level, scope, format, args); } ``` std.process.exit is a problem.
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
hexops/mach#1212
No description provided.