Fix new log function options for zig

This commit is contained in:
Mitchell Hashimoto
2023-01-26 09:10:09 -08:00
parent f2b59353ab
commit e438539a14
2 changed files with 54 additions and 48 deletions

View File

@ -142,19 +142,20 @@ pub fn tracy_enabled() bool {
return options.tracy_enabled;
}
// Our log level is always at least info in every build mode.
pub const log_level: std.log.Level = switch (builtin.mode) {
pub const std_options = struct {
// Our log level is always at least info in every build mode.
pub const log_level: std.log.Level = switch (builtin.mode) {
.Debug => .debug,
else => .info,
};
};
// The function std.log will call.
pub fn log(
// The function std.log will call.
pub fn logFn(
comptime level: std.log.Level,
comptime scope: @TypeOf(.EnumLiteral),
comptime format: []const u8,
args: anytype,
) void {
) void {
// Stuff we can do before the lock
const level_txt = comptime level.asText();
const prefix = if (scope == .default) ": " else "(" ++ @tagName(scope) ++ "): ";
@ -186,7 +187,8 @@ pub fn log(
// Always try default to send to stderr
const stderr = std.io.getStdErr().writer();
nosuspend stderr.print(level_txt ++ prefix ++ format ++ "\n", args) catch return;
}
}
};
fn glfwErrorCallback(code: glfw.Error, desc: [:0]const u8) void {
std.log.warn("glfw error={} message={s}", .{ code, desc });

View File

@ -4,17 +4,21 @@ const std = @import("std");
const builtin = @import("builtin");
pub usingnamespace @import("os/wasm.zig");
pub usingnamespace @import("os/wasm/log.zig");
pub usingnamespace @import("font/main.zig");
pub usingnamespace @import("terminal/main.zig");
pub usingnamespace @import("config.zig").Wasm;
pub usingnamespace @import("App.zig").Wasm;
// Set our log level. We try to get as much logging as possible but in
// ReleaseSmall mode where we're optimizing for space, we elevate the
// log level.
pub const log_level: std.log.Level = switch (builtin.mode) {
pub const std_options = struct {
// Set our log level. We try to get as much logging as possible but in
// ReleaseSmall mode where we're optimizing for space, we elevate the
// log level.
pub const log_level: std.log.Level = switch (builtin.mode) {
.Debug => .debug,
.ReleaseSmall => .warn,
else => .info,
};
// Set our log function
pub const logFn = @import("os/wasm/log.zig").log;
};