mirror of
https://github.com/lightpanda-io/browser.git
synced 2025-10-30 15:41:48 +00:00
Emit Log.addEntry
Currently, this hooks a single log.Interceptor into the logging framework, but changing it to take a list shouldn't be too hard. Biggest issue is who will own it, as we'd need an allocator to maintain a list / lookup (which log doesn't currently have). Uses logFmt format, and, for now, always filters out debug messages and a few particularly verbose scopes.
This commit is contained in:
@@ -30,6 +30,7 @@ const Session = @import("../browser/session.zig").Session;
|
||||
const Page = @import("../browser/page.zig").Page;
|
||||
const Incrementing = @import("../id.zig").Incrementing;
|
||||
const Notification = @import("../notification.zig").Notification;
|
||||
const LogInterceptor = @import("domains/log.zig").LogInterceptor;
|
||||
const InterceptState = @import("domains/fetch.zig").InterceptState;
|
||||
|
||||
pub const URL_BASE = "chrome://newtab/";
|
||||
@@ -338,6 +339,8 @@ pub fn BrowserContext(comptime CDP_T: type) type {
|
||||
|
||||
intercept_state: InterceptState,
|
||||
|
||||
log_interceptor: LogInterceptor(Self),
|
||||
|
||||
// When network is enabled, we'll capture the transfer.id -> body
|
||||
// This is awfully memory intensive, but our underlying http client and
|
||||
// its users (script manager and page) correctly do not hold the body
|
||||
@@ -378,6 +381,7 @@ pub fn BrowserContext(comptime CDP_T: type) type {
|
||||
.notification_arena = cdp.notification_arena.allocator(),
|
||||
.intercept_state = try InterceptState.init(allocator),
|
||||
.captured_responses = .empty,
|
||||
.log_interceptor = LogInterceptor(Self).init(allocator, self),
|
||||
};
|
||||
self.node_search_list = Node.Search.List.init(allocator, &self.node_registry);
|
||||
errdefer self.deinit();
|
||||
@@ -389,6 +393,10 @@ pub fn BrowserContext(comptime CDP_T: type) type {
|
||||
}
|
||||
|
||||
pub fn deinit(self: *Self) void {
|
||||
// safe to call even if never registered
|
||||
log.unregisterInterceptor();
|
||||
self.log_interceptor.deinit();
|
||||
|
||||
self.inspector.deinit();
|
||||
|
||||
// abort all intercepted requests before closing the sesion/page
|
||||
@@ -496,6 +504,18 @@ pub fn BrowserContext(comptime CDP_T: type) type {
|
||||
self.cdp.browser.notification.unregister(.page_network_almost_idle, self);
|
||||
}
|
||||
|
||||
pub fn logEnable(self: *Self) void {
|
||||
log.registerInterceptor(.{
|
||||
.ctx = &self.log_interceptor,
|
||||
.done = LogInterceptor(Self).done,
|
||||
.writer = LogInterceptor(Self).writer,
|
||||
});
|
||||
}
|
||||
|
||||
pub fn logDisable(_: *const Self) void {
|
||||
log.unregisterInterceptor();
|
||||
}
|
||||
|
||||
pub fn onPageRemove(ctx: *anyopaque, _: Notification.PageRemove) !void {
|
||||
const self: *Self = @ptrCast(@alignCast(ctx));
|
||||
try @import("domains/page.zig").pageRemove(self);
|
||||
|
||||
Reference in New Issue
Block a user