Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ability to turn off logging #1212

Open
wooster0 opened this issue Jun 6, 2024 · 1 comment
Open

Ability to turn off logging #1212

wooster0 opened this issue Jun 6, 2024 · 1 comment
Labels
feedback needs-triage Issues that need triaging

Comments

@wooster0
Copy link

wooster0 commented Jun 6, 2024

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.

@wooster0 wooster0 added feedback needs-triage Issues that need triaging labels Jun 6, 2024
@pfgithub
Copy link
Contributor

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feedback needs-triage Issues that need triaging
Projects
None yet
Development

No branches or pull requests

2 participants