feat: redirect std.log to log service

This commit is contained in:
CJ van den Berg 2024-05-10 23:35:14 +02:00
parent ec1fcd475b
commit 76d1e7e34d
2 changed files with 21 additions and 0 deletions

View file

@ -180,3 +180,19 @@ pub fn subscribe() tp.result {
pub fn unsubscribe() tp.result {
return tp.env.get().proc("log").send(.{"unsubscribe"});
}
pub fn std_log_function(
comptime level: std.log.Level,
comptime scope: @TypeOf(.EnumLiteral),
comptime format: []const u8,
args: anytype,
) void {
const prefix = "[" ++ comptime level.asText() ++ "] ";
var buf: [max_log_message]u8 = undefined;
const output = std.fmt.bufPrint(&buf, prefix ++ format, args) catch "MESSAGE TOO LARGE";
if (level == .err) {
tp.env.get().proc("log").send(.{ "log", "error", @tagName(scope), "std.log", "->", output }) catch {};
} else {
tp.env.get().proc("log").send(.{ "log", @tagName(scope), output }) catch {};
}
}

View file

@ -14,6 +14,11 @@ const log = @import("log");
pub const application_name = "flow";
pub const application_logo = "󱞏 ";
pub const std_options = .{
.log_level = .debug,
.logFn = log.std_log_function,
};
pub fn main() anyerror!void {
const params = comptime clap.parseParamsComptime(
\\-h, --help Display this help and exit.