move log overrides into std_options (#902)

This commit is contained in:
Lee Cannon 2023-01-10 21:52:03 +00:00 committed by GitHub
parent bbbd54498d
commit 20d29fd491
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -11,28 +11,30 @@ const debug = @import("debug.zig");
const logger = std.log.scoped(.main); const logger = std.log.scoped(.main);
// Always set this to debug to make std.log call into our handler, then control the runtime
// value in the definition below.
pub const log_level = .debug;
var actual_log_level: std.log.Level = switch (zig_builtin.mode) { var actual_log_level: std.log.Level = switch (zig_builtin.mode) {
.Debug => .debug, .Debug => .debug,
else => @intToEnum(std.log.Level, @enumToInt(build_options.log_level)), // temporary fix to build failing on release-safe due to a Zig bug else => @intToEnum(std.log.Level, @enumToInt(build_options.log_level)), // temporary fix to build failing on release-safe due to a Zig bug
}; };
pub fn log( pub const std_options = struct {
comptime level: std.log.Level, // Always set this to debug to make std.log call into our handler, then control the runtime
comptime scope: @TypeOf(.EnumLiteral), // value in the definition below.
comptime format: []const u8, pub const log_level = .debug;
args: anytype,
) void {
if (@enumToInt(level) > @enumToInt(actual_log_level)) return;
const level_txt = comptime level.asText(); pub fn logFn(
comptime level: std.log.Level,
comptime scope: @TypeOf(.EnumLiteral),
comptime format: []const u8,
args: anytype,
) void {
if (@enumToInt(level) > @enumToInt(actual_log_level)) return;
std.debug.print("{s:<5}: ({s:^6}): ", .{ level_txt, @tagName(scope) }); const level_txt = comptime level.asText();
std.debug.print(format ++ "\n", args);
} std.debug.print("{s:<5}: ({s:^6}): ", .{ level_txt, @tagName(scope) });
std.debug.print(format ++ "\n", args);
}
};
fn loop( fn loop(
server: *Server, server: *Server,
@ -86,7 +88,7 @@ fn loop(
server.processJsonRpc(&arena, json_message); server.processJsonRpc(&arena, json_message);
if(server.status == .exiting_success or server.status == .exiting_failure) return; if (server.status == .exiting_success or server.status == .exiting_failure) return;
} }
} }