diff --git a/src/log.zig b/src/log.zig index c635d64..e4c2ec3 100644 --- a/src/log.zig +++ b/src/log.zig @@ -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 {}; + } +} diff --git a/src/main.zig b/src/main.zig index 96d1e32..f2c4873 100644 --- a/src/main.zig +++ b/src/main.zig @@ -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.