feat: write early log output to stderr/stdout until TUI is initialized
This commit is contained in:
parent
8789e8b89c
commit
b913b8ad87
2 changed files with 34 additions and 1 deletions
31
src/log.zig
31
src/log.zig
|
@ -11,6 +11,8 @@ subscriber: ?tp.pid,
|
||||||
heap: [32 + 1024]u8,
|
heap: [32 + 1024]u8,
|
||||||
fba: std.heap.FixedBufferAllocator,
|
fba: std.heap.FixedBufferAllocator,
|
||||||
msg_store: MsgStoreT,
|
msg_store: MsgStoreT,
|
||||||
|
no_stdout: bool = false,
|
||||||
|
no_stderr: bool = false,
|
||||||
|
|
||||||
const MsgStoreT = std.DoublyLinkedList([]u8);
|
const MsgStoreT = std.DoublyLinkedList([]u8);
|
||||||
const Receiver = tp.Receiver(*Self);
|
const Receiver = tp.Receiver(*Self);
|
||||||
|
@ -79,12 +81,23 @@ fn store_reset(self: *Self) void {
|
||||||
|
|
||||||
fn receive(self: *Self, from: tp.pid_ref, m: tp.message) tp.result {
|
fn receive(self: *Self, from: tp.pid_ref, m: tp.message) tp.result {
|
||||||
errdefer self.deinit();
|
errdefer self.deinit();
|
||||||
if (try m.match(.{ "log", tp.more })) {
|
var output: []const u8 = undefined;
|
||||||
|
if (try m.match(.{ "log", "error", tp.string, "std.log", "->", tp.extract(&output) })) {
|
||||||
if (self.subscriber) |subscriber| {
|
if (self.subscriber) |subscriber| {
|
||||||
subscriber.send_raw(m) catch {};
|
subscriber.send_raw(m) catch {};
|
||||||
} else {
|
} else {
|
||||||
self.store(m);
|
self.store(m);
|
||||||
}
|
}
|
||||||
|
if (!self.no_stderr)
|
||||||
|
std.io.getStdErr().writer().print("{s}\n", .{output}) catch {};
|
||||||
|
} else if (try m.match(.{ "log", tp.string, tp.extract(&output) })) {
|
||||||
|
if (self.subscriber) |subscriber| {
|
||||||
|
subscriber.send_raw(m) catch {};
|
||||||
|
} else {
|
||||||
|
self.store(m);
|
||||||
|
}
|
||||||
|
if (!self.no_stdout)
|
||||||
|
std.io.getStdOut().writer().print("{s}\n", .{output}) catch {};
|
||||||
} else if (try m.match(.{"subscribe"})) {
|
} else if (try m.match(.{"subscribe"})) {
|
||||||
// log("subscribed");
|
// log("subscribed");
|
||||||
if (self.subscriber) |*s| s.deinit();
|
if (self.subscriber) |*s| s.deinit();
|
||||||
|
@ -95,6 +108,14 @@ fn receive(self: *Self, from: tp.pid_ref, m: tp.message) tp.result {
|
||||||
if (self.subscriber) |*s| s.deinit();
|
if (self.subscriber) |*s| s.deinit();
|
||||||
self.subscriber = null;
|
self.subscriber = null;
|
||||||
self.store_reset();
|
self.store_reset();
|
||||||
|
} else if (try m.match(.{ "stdout", "enable" })) {
|
||||||
|
self.no_stdout = false;
|
||||||
|
} else if (try m.match(.{ "stdout", "disable" })) {
|
||||||
|
self.no_stdout = true;
|
||||||
|
} else if (try m.match(.{ "stderr", "enable" })) {
|
||||||
|
self.no_stderr = false;
|
||||||
|
} else if (try m.match(.{ "stderr", "disable" })) {
|
||||||
|
self.no_stderr = true;
|
||||||
} else if (try m.match(.{"shutdown"})) {
|
} else if (try m.match(.{"shutdown"})) {
|
||||||
return tp.exit_normal();
|
return tp.exit_normal();
|
||||||
}
|
}
|
||||||
|
@ -202,6 +223,14 @@ pub fn unsubscribe() tp.result {
|
||||||
return tp.env.get().proc("log").send(.{"unsubscribe"});
|
return tp.env.get().proc("log").send(.{"unsubscribe"});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn stdout(state: enum { enable, disable }) void {
|
||||||
|
tp.env.get().proc("log").send(.{ "stdout", state }) catch {};
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn stderr(state: enum { enable, disable }) void {
|
||||||
|
tp.env.get().proc("log").send(.{ "stderr", state }) catch {};
|
||||||
|
}
|
||||||
|
|
||||||
var std_log_pid: ?tp.pid_ref = null;
|
var std_log_pid: ?tp.pid_ref = null;
|
||||||
|
|
||||||
pub fn set_std_log_pid(pid: ?tp.pid_ref) void {
|
pub fn set_std_log_pid(pid: ?tp.pid_ref) void {
|
||||||
|
|
|
@ -103,6 +103,8 @@ const InitError = error{
|
||||||
keybind.LoadError;
|
keybind.LoadError;
|
||||||
|
|
||||||
fn init(allocator: Allocator) InitError!*Self {
|
fn init(allocator: Allocator) InitError!*Self {
|
||||||
|
log.stdout(.disable);
|
||||||
|
|
||||||
var conf, const conf_bufs = root.read_config(@import("config"), allocator);
|
var conf, const conf_bufs = root.read_config(@import("config"), allocator);
|
||||||
|
|
||||||
if (@hasDecl(renderer, "install_crash_handler") and conf.start_debugger_on_crash)
|
if (@hasDecl(renderer, "install_crash_handler") and conf.start_debugger_on_crash)
|
||||||
|
@ -157,6 +159,8 @@ fn init(allocator: Allocator) InitError!*Self {
|
||||||
self.rdr_.dispatch_event = dispatch_event;
|
self.rdr_.dispatch_event = dispatch_event;
|
||||||
try self.rdr_.run();
|
try self.rdr_.run();
|
||||||
|
|
||||||
|
log.stderr(.disable);
|
||||||
|
|
||||||
try project_manager.start();
|
try project_manager.start();
|
||||||
|
|
||||||
try frame_clock.start();
|
try frame_clock.start();
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue