move log overrides into std_options
(#902)
This commit is contained in:
parent
bbbd54498d
commit
20d29fd491
18
src/main.zig
18
src/main.zig
@ -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 {
|
||||||
|
// 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;
|
||||||
|
|
||||||
|
pub fn logFn(
|
||||||
comptime level: std.log.Level,
|
comptime level: std.log.Level,
|
||||||
comptime scope: @TypeOf(.EnumLiteral),
|
comptime scope: @TypeOf(.EnumLiteral),
|
||||||
comptime format: []const u8,
|
comptime format: []const u8,
|
||||||
args: anytype,
|
args: anytype,
|
||||||
) void {
|
) void {
|
||||||
if (@enumToInt(level) > @enumToInt(actual_log_level)) return;
|
if (@enumToInt(level) > @enumToInt(actual_log_level)) return;
|
||||||
|
|
||||||
const level_txt = comptime level.asText();
|
const level_txt = comptime level.asText();
|
||||||
|
|
||||||
std.debug.print("{s:<5}: ({s:^6}): ", .{ level_txt, @tagName(scope) });
|
std.debug.print("{s:<5}: ({s:^6}): ", .{ level_txt, @tagName(scope) });
|
||||||
std.debug.print(format ++ "\n", args);
|
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;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user