feat: redirect std.log to log service
This commit is contained in:
parent
ec1fcd475b
commit
76d1e7e34d
2 changed files with 21 additions and 0 deletions
16
src/log.zig
16
src/log.zig
|
@ -180,3 +180,19 @@ pub fn subscribe() tp.result {
|
||||||
pub fn unsubscribe() tp.result {
|
pub fn unsubscribe() tp.result {
|
||||||
return tp.env.get().proc("log").send(.{"unsubscribe"});
|
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 {};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -14,6 +14,11 @@ const log = @import("log");
|
||||||
pub const application_name = "flow";
|
pub const application_name = "flow";
|
||||||
pub const application_logo = " ";
|
pub const application_logo = " ";
|
||||||
|
|
||||||
|
pub const std_options = .{
|
||||||
|
.log_level = .debug,
|
||||||
|
.logFn = log.std_log_function,
|
||||||
|
};
|
||||||
|
|
||||||
pub fn main() anyerror!void {
|
pub fn main() anyerror!void {
|
||||||
const params = comptime clap.parseParamsComptime(
|
const params = comptime clap.parseParamsComptime(
|
||||||
\\-h, --help Display this help and exit.
|
\\-h, --help Display this help and exit.
|
||||||
|
|
Loading…
Add table
Reference in a new issue