From 98d51f6d24ef8cc9166833e89c26e7663dbb5831 Mon Sep 17 00:00:00 2001 From: foxfromabyss Date: Fri, 5 Feb 2021 09:46:18 +0100 Subject: [PATCH] Use std.log instead of log.zig --- river/Cursor.zig | 13 ++-- river/InputManager.zig | 11 +-- river/Keyboard.zig | 10 +-- river/LayerSurface.zig | 11 +-- river/Output.zig | 17 ++--- river/OutputStatus.zig | 5 +- river/Root.zig | 33 ++++----- river/Seat.zig | 20 +++--- river/Server.zig | 15 ++-- river/StatusManager.zig | 13 ++-- river/View.zig | 13 ++-- river/XdgPopup.zig | 5 +- river/XdgToplevel.zig | 5 +- river/log.zig | 154 ---------------------------------------- river/main.zig | 46 +++++++++--- river/render.zig | 5 +- 16 files changed, 127 insertions(+), 249 deletions(-) delete mode 100644 river/log.zig diff --git a/river/Cursor.zig b/river/Cursor.zig index 3904dfb..0f72868 100644 --- a/river/Cursor.zig +++ b/river/Cursor.zig @@ -26,7 +26,6 @@ const wl = wayland.server.wl; const zwlr = wayland.server.zwlr; const c = @import("c.zig"); -const log = @import("log.zig"); const util = @import("util.zig"); const Box = @import("Box.zig"); @@ -51,6 +50,8 @@ const Mode = union(enum) { const default_size = 24; +const log = std.log.scoped(.cursor); + /// Current cursor mode as well as any state needed to implement that mode mode: Mode = .passthrough, @@ -126,7 +127,7 @@ pub fn setTheme(self: *Self, theme: ?[*:0]const u8, _size: ?u32) !void { while (it) |node| : (it = node.next) { const wlr_output = node.data.wlr_output; self.xcursor_manager.load(wlr_output.scale) catch - log.err(.cursor, "failed to load xcursor theme '{}' at scale {}", .{ theme, wlr_output.scale }); + log.err("failed to load xcursor theme '{}' at scale {}", .{ theme, wlr_output.scale }); } // If this cursor belongs to the default seat, set the xcursor environment @@ -139,7 +140,7 @@ pub fn setTheme(self: *Self, theme: ?[*:0]const u8, _size: ?u32) !void { if (build_options.xwayland) { self.xcursor_manager.load(1) catch { - log.err(.cursor, "failed to load xcursor theme '{}' at scale 1", .{theme}); + log.err("failed to load xcursor theme '{}' at scale 1", .{theme}); return; }; const wlr_xcursor = self.xcursor_manager.getXcursor("left_ptr", 1).?; @@ -316,7 +317,7 @@ fn handleRequestSetCursor( // provided surface as the cursor image. It will set the hardware cursor // on the output that it's currently on and continue to do so as the // cursor moves between outputs. - log.debug(.cursor, "focused client set cursor", .{}); + log.debug("focused client set cursor", .{}); self.wlr_cursor.setSurface(event.surface, event.hotspot_x, event.hotspot_y); } } @@ -408,7 +409,7 @@ fn surfaceAtFilter(view: *View, filter_tags: u32) bool { /// Enter move or resize mode pub fn enterMode(self: *Self, mode: @TagType(Mode), view: *View) void { - log.debug(.cursor, "enter {} mode", .{@tagName(mode)}); + log.debug("enter {} mode", .{@tagName(mode)}); self.seat.focus(view); @@ -454,7 +455,7 @@ pub fn enterMode(self: *Self, mode: @TagType(Mode), view: *View) void { fn leaveMode(self: *Self, event: *wlr.Pointer.event.Button) void { std.debug.assert(self.mode != .passthrough); - log.debug(.cursor, "leave {} mode", .{@tagName(self.mode)}); + log.debug("leave {} mode", .{@tagName(self.mode)}); // If we were in down mode, we need pass along the release event if (self.mode == .down) diff --git a/river/InputManager.zig b/river/InputManager.zig index f085f82..d1c95b4 100644 --- a/river/InputManager.zig +++ b/river/InputManager.zig @@ -22,7 +22,6 @@ const std = @import("std"); const wlr = @import("wlroots"); const wl = @import("wayland").server.wl; -const log = @import("log.zig"); const util = @import("util.zig"); const Seat = @import("Seat.zig"); @@ -31,6 +30,8 @@ const View = @import("View.zig"); const default_seat_name = "default"; +const log = std.log.scoped(.input_manager); + server: *Server, new_input: wl.Listener(*wlr.InputDevice) = wl.Listener(*wlr.InputDevice).init(handleNewInput), @@ -120,7 +121,7 @@ fn handleInhibitActivate( ) void { const self = @fieldParentPtr(Self, "inhibit_activate", listener); - log.debug(.input_manager, "input inhibitor activated", .{}); + log.debug("input inhibitor activated", .{}); var seat_it = self.seats.first; while (seat_it) |seat_node| : (seat_it = seat_node.next) { @@ -141,7 +142,7 @@ fn handleInhibitDeactivate( ) void { const self = @fieldParentPtr(Self, "inhibit_deactivate", listener); - log.debug(.input_manager, "input inhibitor deactivated", .{}); + log.debug("input inhibitor deactivated", .{}); self.exclusive_client = null; @@ -178,11 +179,11 @@ fn handleNewVirtualPointer( // TODO Support multiple seats and don't ignore if (event.suggested_seat != null) { - log.debug(.input_manager, "Ignoring seat suggestion from virtual pointer", .{}); + log.debug("Ignoring seat suggestion from virtual pointer", .{}); } // TODO dont ignore output suggestion if (event.suggested_output != null) { - log.debug(.input_manager, "Ignoring output suggestion from virtual pointer", .{}); + log.debug("Ignoring output suggestion from virtual pointer", .{}); } self.defaultSeat().addDevice(&event.new_pointer.input_device); diff --git a/river/Keyboard.zig b/river/Keyboard.zig index 19c3a6e..3642061 100644 --- a/river/Keyboard.zig +++ b/river/Keyboard.zig @@ -22,11 +22,12 @@ const wlr = @import("wlroots"); const wl = @import("wayland").server.wl; const xkb = @import("xkbcommon"); -const log = @import("log.zig"); const util = @import("util.zig"); const Seat = @import("Seat.zig"); +const log = std.log.scoped(.keyboard); + seat: *Seat, input_device: *wlr.InputDevice, @@ -147,13 +148,14 @@ fn handleDestroy(listener: *wl.Listener(*wlr.Keyboard), wlr_keyboard: *wlr.Keybo fn handleBuiltinMapping(self: Self, keysym: xkb.Keysym) bool { switch (@enumToInt(keysym)) { @enumToInt(xkb.Keysym.XF86Switch_VT_1)...@enumToInt(xkb.Keysym.XF86Switch_VT_12) => { - log.debug(.keyboard, "switch VT keysym received", .{}); + log.debug("switch VT keysym received", .{}); const backend = self.seat.input_manager.server.backend; if (backend.isMulti()) { if (backend.getSession()) |session| { const vt = @enumToInt(keysym) - @enumToInt(xkb.Keysym.XF86Switch_VT_1) + 1; - log.notice(.server, "switching to VT {}", .{vt}); - session.changeVt(vt) catch log.err(.server, "changing VT failed", .{}); + const log_server = std.log.scoped(.server); + log_server.notice("switching to VT {}", .{vt}); + session.changeVt(vt) catch log_server.err("changing VT failed", .{}); } } return true; diff --git a/river/LayerSurface.zig b/river/LayerSurface.zig index 54de498..65d7e28 100644 --- a/river/LayerSurface.zig +++ b/river/LayerSurface.zig @@ -21,13 +21,14 @@ const std = @import("std"); const wlr = @import("wlroots"); const wl = @import("wayland").server.wl; -const log = @import("log.zig"); const util = @import("util.zig"); const Box = @import("Box.zig"); const Output = @import("Output.zig"); const XdgPopup = @import("XdgPopup.zig"); +const log = std.log.scoped(.layer_shell); + output: *Output, wlr_layer_surface: *wlr.LayerSurfaceV1, @@ -68,7 +69,7 @@ pub fn init(self: *Self, output: *Output, wlr_layer_surface: *wlr.LayerSurfaceV1 fn handleDestroy(listener: *wl.Listener(*wlr.LayerSurfaceV1), wlr_layer_surface: *wlr.LayerSurfaceV1) void { const self = @fieldParentPtr(Self, "destroy", listener); - log.debug(.layer_shell, "layer surface '{}' destroyed", .{self.wlr_layer_surface.namespace}); + log.debug("layer surface '{}' destroyed", .{self.wlr_layer_surface.namespace}); // Remove listeners active the entire lifetime of the layer surface self.destroy.link.remove(); @@ -82,7 +83,7 @@ fn handleDestroy(listener: *wl.Listener(*wlr.LayerSurfaceV1), wlr_layer_surface: fn handleMap(listener: *wl.Listener(*wlr.LayerSurfaceV1), wlr_layer_surface: *wlr.LayerSurfaceV1) void { const self = @fieldParentPtr(Self, "map", listener); - log.debug(.layer_shell, "layer surface '{}' mapped", .{wlr_layer_surface.namespace}); + log.debug("layer surface '{}' mapped", .{wlr_layer_surface.namespace}); // Add listeners that are only active while mapped wlr_layer_surface.surface.events.commit.add(&self.commit); @@ -97,7 +98,7 @@ fn handleMap(listener: *wl.Listener(*wlr.LayerSurfaceV1), wlr_layer_surface: *wl fn handleUnmap(listener: *wl.Listener(*wlr.LayerSurfaceV1), wlr_layer_surface: *wlr.LayerSurfaceV1) void { const self = @fieldParentPtr(Self, "unmap", listener); - log.debug(.layer_shell, "layer surface '{}' unmapped", .{self.wlr_layer_surface.namespace}); + log.debug("layer surface '{}' unmapped", .{self.wlr_layer_surface.namespace}); // remove listeners only active while the layer surface is mapped self.commit.link.remove(); @@ -134,7 +135,7 @@ fn handleCommit(listener: *wl.Listener(*wlr.Surface), wlr_surface: *wlr.Surface) const self = @fieldParentPtr(Self, "commit", listener); if (self.wlr_layer_surface.output == null) { - log.err(.layer_shell, "layer surface committed with null output", .{}); + log.err("layer surface committed with null output", .{}); return; } diff --git a/river/Output.zig b/river/Output.zig index bbedcc6..b9600be 100644 --- a/river/Output.zig +++ b/river/Output.zig @@ -26,7 +26,6 @@ const wl = wayland.server.wl; const zwlr = wayland.server.zwlr; const c = @import("c.zig"); -const log = @import("log.zig"); const render = @import("render.zig"); const util = @import("util.zig"); @@ -44,6 +43,8 @@ const State = struct { tags: u32, }; +const log = std.log.scoped(.layout); + root: *Root, wlr_output: *wlr.Output, @@ -133,7 +134,7 @@ pub fn init(self: *Self, root: *Root, wlr_output: *wlr.Output) !void { while (it) |node| : (it = node.next) { const seat = &node.data; seat.cursor.xcursor_manager.load(wlr_output.scale) catch - log.err(.cursor, "failed to load xcursor theme at scale {}", .{wlr_output.scale}); + std.log.scoped(.cursor).err("failed to load xcursor theme at scale {}", .{wlr_output.scale}); } const effective_resolution = self.getEffectiveResolution(); @@ -303,11 +304,11 @@ pub fn arrangeViews(self: *Self) void { self.layoutExternal(layout_count) catch |err| { switch (err) { - LayoutError.BadExitCode => log.err(.layout, "layout command exited with non-zero return code", .{}), - LayoutError.WrongViewCount => log.err(.layout, "mismatch between window configuration and visible window counts", .{}), - else => log.err(.layout, "failed to use external layout: {}", .{err}), + LayoutError.BadExitCode => log.err("layout command exited with non-zero return code", .{}), + LayoutError.WrongViewCount => log.err("mismatch between window configuration and visible window counts", .{}), + else => log.err("failed to use external layout: {}", .{err}), } - log.err(.layout, "falling back to internal layout", .{}); + log.err("falling back to internal layout", .{}); self.layoutFull(layout_count); }; } @@ -484,7 +485,7 @@ fn arrangeLayer( } // Tell the client to assume the new size - log.debug(.layer_shell, "send configure, {} x {}", .{ layer_surface.box.width, layer_surface.box.height }); + std.log.scoped(.layer_shell).debug("send configure, {} x {}", .{ layer_surface.box.width, layer_surface.box.height }); layer_surface.wlr_layer_surface.configure(layer_surface.box.width, layer_surface.box.height); } } @@ -495,7 +496,7 @@ fn handleDestroy(listener: *wl.Listener(*wlr.Output), wlr_output: *wlr.Output) v const self = @fieldParentPtr(Self, "destroy", listener); const root = self.root; - log.debug(.server, "output '{}' destroyed", .{self.wlr_output.name}); + std.log.scoped(.server).debug("output '{}' destroyed", .{self.wlr_output.name}); root.server.options_manager.handleOutputDestroy(self); diff --git a/river/OutputStatus.zig b/river/OutputStatus.zig index 4b8e22c..cc6a041 100644 --- a/river/OutputStatus.zig +++ b/river/OutputStatus.zig @@ -22,13 +22,14 @@ const wayland = @import("wayland"); const wl = wayland.server.wl; const zriver = wayland.server.zriver; -const log = @import("log.zig"); const util = @import("util.zig"); const Output = @import("Output.zig"); const View = @import("View.zig"); const ViewStack = @import("view_stack.zig").ViewStack; +const log = std.log.scoped(.river_status); + output: *Output, output_status: *zriver.OutputStatusV1, @@ -63,7 +64,7 @@ pub fn sendViewTags(self: Self) void { if (node.view.destroying) continue; view_tags.append(node.view.current.tags) catch { self.output_status.postNoMemory(); - log.crit(.river_status, "out of memory", .{}); + log.crit("out of memory", .{}); return; }; } diff --git a/river/Root.zig b/river/Root.zig index e05d025..4c70a58 100644 --- a/river/Root.zig +++ b/river/Root.zig @@ -22,7 +22,6 @@ const std = @import("std"); const wlr = @import("wlroots"); const wl = @import("wayland").server.wl; -const log = @import("log.zig"); const util = @import("util.zig"); const Output = @import("Output.zig"); @@ -124,7 +123,7 @@ pub fn deinit(self: *Self) void { fn handleNewOutput(listener: *wl.Listener(*wlr.Output), wlr_output: *wlr.Output) void { const self = @fieldParentPtr(Self, "new_output", listener); - log.debug(.output_manager, "new output {}", .{wlr_output.name}); + std.log.scoped(.output_manager).debug("new output {}", .{wlr_output.name}); const node = util.gpa.create(std.TailQueue(Output).Node) catch { wlr_output.destroy(); @@ -293,27 +292,26 @@ pub fn startTransaction(self: *Self) void { } if (self.pending_configures > 0) { - log.debug( - .transaction, + std.log.scoped(.transaction).debug( "started transaction with {} pending configure(s)", .{self.pending_configures}, ); // Set timeout to 200ms self.transaction_timer.timerUpdate(200) catch { - log.err(.transaction, "failed to update timer", .{}); + std.log.scoped(.transaction).err("failed to update timer", .{}); self.commitTransaction(); }; } else { // No views need configures, clear the current timer in case we are // interrupting another transaction and commit. - self.transaction_timer.timerUpdate(0) catch log.err(.transaction, "error disarming timer", .{}); + self.transaction_timer.timerUpdate(0) catch std.log.scoped(.transaction).err("error disarming timer", .{}); self.commitTransaction(); } } fn handleTimeout(self: *Self) callconv(.C) c_int { - log.err(.transaction, "timeout occurred, some imperfect frames may be shown", .{}); + std.log.scoped(.transaction).err("timeout occurred, some imperfect frames may be shown", .{}); self.pending_configures = 0; self.commitTransaction(); @@ -325,7 +323,7 @@ pub fn notifyConfigured(self: *Self) void { self.pending_configures -= 1; if (self.pending_configures == 0) { // Disarm the timer, as we didn't timeout - self.transaction_timer.timerUpdate(0) catch log.err(.transaction, "error disarming timer", .{}); + self.transaction_timer.timerUpdate(0) catch std.log.scoped(.transaction).err("error disarming timer", .{}); self.commitTransaction(); } } @@ -346,8 +344,7 @@ fn commitTransaction(self: *Self) void { const output_tags_changed = output.pending.tags != output.current.tags; output.current = output.pending; if (output_tags_changed) { - log.debug( - .output, + std.log.scoped(.output).debug( "changing current focus: {b:0>10} to {b:0>10}", .{ output.current.tags, output.pending.tags }, ); @@ -392,7 +389,7 @@ fn handleLayoutChange( const self = @fieldParentPtr(Self, "layout_change", listener); const config = self.ouputConfigFromCurrent() catch { - log.crit(.output_manager, "out of memory", .{}); + std.log.scoped(.output_manager).crit("out of memory", .{}); return; }; self.output_manager.setConfiguration(config); @@ -413,7 +410,7 @@ fn handleManagerApply( // Send the config that was actually applied const applied_config = self.ouputConfigFromCurrent() catch { - log.crit(.output_manager, "out of memory", .{}); + std.log.scoped(.output_manager).crit("out of memory", .{}); return; }; self.output_manager.setConfiguration(applied_config); @@ -450,7 +447,7 @@ fn applyOutputConfig(self: *Self, config: *wlr.OutputConfigurationV1) bool { // Since we have done a successful test commit, this will only fail // due to error in the output's backend implementation. output.wlr_output.commit() catch - log.err(.output_manager, "output commit failed for {}", .{output.wlr_output.name}); + std.log.scoped(.output_manager).err("output commit failed for {}", .{output.wlr_output.name}); if (output.wlr_output.enabled) { // Moves the output if it is already in the layout @@ -488,8 +485,7 @@ fn testOutputConfig(config: *wlr.OutputConfigurationV1, rollback: bool) bool { (@intToFloat(f32, height) / scale < min_size); if (too_small) { - log.info( - .output_manager, + std.log.scoped(.output_manager).info( "The requested output resolution {}x{} scaled with {} for {} would be too small.", .{ width, height, scale, wlr_output.name }, ); @@ -521,7 +517,7 @@ fn applyHeadToOutput(head: *wlr.OutputConfigurationV1.Head, wlr_output: *wlr.Out if (head.state.mode) |mode| { wlr_output.setMode(mode); } else { - log.info(.output_manager, "custom modes are not supported until the next wlroots release: ignoring", .{}); + std.log.scoped(.output_manager).info("custom modes are not supported until the next wlroots release: ignoring", .{}); // TODO(wlroots) uncomment the following lines when wlroots 0.13.0 is released // See https://github.com/swaywm/wlroots/pull/2517 //const custom_mode = &head.state.custom_mode; @@ -565,13 +561,12 @@ fn handlePowerManagerSetMode( const enable = event.mode == .on; const log_text = if (enable) "Enabling" else "Disabling"; - log.debug( - .output_manager, + std.log.scoped(.output_manager).debug( "{} dpms for output {}", .{ log_text, event.output.name }, ); event.output.enable(enable); event.output.commit() catch - log.err(.server, "output commit failed for {}", .{event.output.name}); + std.log.scoped(.server).err("output commit failed for {}", .{event.output.name}); } diff --git a/river/Seat.zig b/river/Seat.zig index 4953072..6431cd3 100644 --- a/river/Seat.zig +++ b/river/Seat.zig @@ -24,7 +24,6 @@ const wl = @import("wayland").server.wl; const xkb = @import("xkbcommon"); const command = @import("command.zig"); -const log = @import("log.zig"); const util = @import("util.zig"); const DragIcon = @import("DragIcon.zig"); @@ -37,6 +36,8 @@ const SeatStatus = @import("SeatStatus.zig"); const View = @import("View.zig"); const ViewStack = @import("view_stack.zig").ViewStack; +const log = std.log.scoped(.seat); + const FocusTarget = union(enum) { view: *View, layer: *LayerSurface, @@ -302,13 +303,13 @@ pub fn handleMapping( command.Error.Other => out.?, else => command.errToMsg(err), }; - log.err(.command, "{}: {}", .{ args[0], failure_message }); + std.log.scoped(.command).err("{}: {}", .{ args[0], failure_message }); return true; }; if (out) |s| { const stdout = std.io.getStdOut().outStream(); stdout.print("{}", .{s}) catch - |err| log.err(.command, "{}: write to stdout failed {}", .{ args[0], err }); + |err| std.log.scoped(.command).err("{}: write to stdout failed {}", .{ args[0], err }); } return true; } @@ -337,10 +338,11 @@ pub fn addDevice(self: *Self, device: *wlr.InputDevice) void { fn addKeyboard(self: *Self, device: *wlr.InputDevice) !void { const node = try util.gpa.create(std.TailQueue(Keyboard).Node); node.data.init(self, device) catch |err| { + const log_keyboard = std.log.scoped(.keyboard); switch (err) { - error.XkbContextFailed => log.err(.keyboard, "Failed to create XKB context", .{}), - error.XkbKeymapFailed => log.err(.keyboard, "Failed to create XKB keymap", .{}), - error.SetKeymapFailed => log.err(.keyboard, "Failed to set wlr keyboard keymap", .{}), + error.XkbContextFailed => log_keyboard.err("Failed to create XKB context", .{}), + error.XkbKeymapFailed => log_keyboard.err("Failed to create XKB keymap", .{}), + error.SetKeymapFailed => log_keyboard.err("Failed to set wlr keyboard keymap", .{}), } return; }; @@ -371,12 +373,12 @@ fn handleRequestStartDrag( const self = @fieldParentPtr(Self, "request_start_drag", listener); if (!self.wlr_seat.validatePointerGrabSerial(event.origin, event.serial)) { - log.debug(.seat, "ignoring request to start drag, failed to validate serial {}", .{event.serial}); + log.debug("ignoring request to start drag, failed to validate serial {}", .{event.serial}); if (event.drag.source) |source| source.destroy(); return; } - log.debug(.seat, "starting pointer drag", .{}); + log.debug("starting pointer drag", .{}); self.wlr_seat.startPointerDrag(event.drag, event.serial); } @@ -388,7 +390,7 @@ fn handleStartDrag( if (wlr_drag.icon) |wlr_drag_icon| { const node = util.gpa.create(std.SinglyLinkedList(DragIcon).Node) catch { - log.crit(.seat, "out of memory", .{}); + log.crit("out of memory", .{}); return; }; node.data.init(self, wlr_drag_icon); diff --git a/river/Server.zig b/river/Server.zig index 5ea699b..5a6377e 100644 --- a/river/Server.zig +++ b/river/Server.zig @@ -23,7 +23,6 @@ const wlr = @import("wlroots"); const wl = @import("wayland").server.wl; const c = @import("c.zig"); -const log = @import("log.zig"); const util = @import("util.zig"); const Config = @import("Config.zig"); @@ -39,6 +38,8 @@ const View = @import("View.zig"); const ViewStack = @import("view_stack.zig").ViewStack; const XwaylandUnmanaged = @import("XwaylandUnmanaged.zig"); +const log = std.log.scoped(.server); + wl_server: *wl.Server, sigint_source: *wl.EventSource, @@ -168,11 +169,11 @@ fn handleNewXdgSurface(listener: *wl.Listener(*wlr.XdgSurface), xdg_surface: *wl const self = @fieldParentPtr(Self, "new_xdg_surface", listener); if (xdg_surface.role == .popup) { - log.debug(.server, "new xdg_popup", .{}); + log.debug("new xdg_popup", .{}); return; } - log.debug(.server, "new xdg_toplevel", .{}); + log.debug("new xdg_toplevel", .{}); // The View will add itself to the output's view stack on map const output = self.input_manager.defaultSeat().focused_output; @@ -188,7 +189,6 @@ fn handleNewLayerSurface(listener: *wl.Listener(*wlr.LayerSurfaceV1), wlr_layer_ const self = @fieldParentPtr(Self, "new_layer_surface", listener); log.debug( - .server, "New layer surface: namespace {}, layer {}, anchor {}, size {}x{}, margin ({},{},{},{}), exclusive_zone {}", .{ wlr_layer_surface.namespace, @@ -209,12 +209,12 @@ fn handleNewLayerSurface(listener: *wl.Listener(*wlr.LayerSurfaceV1), wlr_layer_ if (wlr_layer_surface.output == null) { const output = self.input_manager.defaultSeat().focused_output; if (output == &self.root.noop_output) { - log.err(.server, "no output available for layer surface '{}'", .{wlr_layer_surface.namespace}); + log.err("no output available for layer surface '{}'", .{wlr_layer_surface.namespace}); wlr_layer_surface.close(); return; } - log.debug(.server, "new layer surface had null output, assigning it to output '{}'", .{ + log.debug("new layer surface had null output, assigning it to output '{}'", .{ output.wlr_output.name, }); wlr_layer_surface.output = output.wlr_output; @@ -233,7 +233,7 @@ fn handleNewXwaylandSurface(listener: *wl.Listener(*wlr.XwaylandSurface), wlr_xw const self = @fieldParentPtr(Self, "new_xwayland_surface", listener); if (wlr_xwayland_surface.override_redirect) { - log.debug(.server, "new unmanaged xwayland surface", .{}); + log.debug("new unmanaged xwayland surface", .{}); // The unmanged surface will add itself to the list of unmanaged views // in Root when it is mapped. const node = util.gpa.create(std.TailQueue(XwaylandUnmanaged).Node) catch return; @@ -242,7 +242,6 @@ fn handleNewXwaylandSurface(listener: *wl.Listener(*wlr.XwaylandSurface), wlr_xw } log.debug( - .server, "new xwayland surface: title '{}', class '{}'", .{ wlr_xwayland_surface.title, wlr_xwayland_surface.class }, ); diff --git a/river/StatusManager.zig b/river/StatusManager.zig index 0cfdec0..6de8877 100644 --- a/river/StatusManager.zig +++ b/river/StatusManager.zig @@ -23,7 +23,6 @@ const wayland = @import("wayland"); const wl = wayland.server.wl; const zriver = wayland.server.zriver; -const log = @import("log.zig"); const util = @import("util.zig"); const Output = @import("Output.zig"); @@ -32,6 +31,8 @@ const Seat = @import("Seat.zig"); const SeatStatus = @import("SeatStatus.zig"); const Server = @import("Server.zig"); +const log = std.log.scoped(.river_status); + global: *wl.Global, server_destroy: wl.Listener(*wl.Server) = wl.Listener(*wl.Server).init(handleServerDestroy), @@ -52,7 +53,7 @@ fn handleServerDestroy(listener: *wl.Listener(*wl.Server), wl_server: *wl.Server fn bind(client: *wl.Client, self: *Self, version: u32, id: u32) callconv(.C) void { const status_manager = zriver.StatusManagerV1.create(client, version, id) catch { client.postNoMemory(); - log.crit(.river_status, "out of memory", .{}); + log.crit("out of memory", .{}); return; }; status_manager.setHandler(*Self, handleRequest, null, self); @@ -72,7 +73,7 @@ fn handleRequest( const node = util.gpa.create(std.SinglyLinkedList(OutputStatus).Node) catch { status_manager.getClient().postNoMemory(); - log.crit(.river_status, "out of memory", .{}); + log.crit("out of memory", .{}); return; }; @@ -83,7 +84,7 @@ fn handleRequest( ) catch { status_manager.getClient().postNoMemory(); util.gpa.destroy(node); - log.crit(.river_status, "out of memory", .{}); + log.crit("out of memory", .{}); return; }; @@ -97,7 +98,7 @@ fn handleRequest( const node = util.gpa.create(std.SinglyLinkedList(SeatStatus).Node) catch { status_manager.getClient().postNoMemory(); - log.crit(.river_status, "out of memory", .{}); + log.crit("out of memory", .{}); return; }; @@ -108,7 +109,7 @@ fn handleRequest( ) catch { status_manager.getClient().postNoMemory(); util.gpa.destroy(node); - log.crit(.river_status, "out of memory", .{}); + log.crit("out of memory", .{}); return; }; diff --git a/river/View.zig b/river/View.zig index 85a5b2f..f4b7447 100644 --- a/river/View.zig +++ b/river/View.zig @@ -24,7 +24,6 @@ const os = std.os; const wlr = @import("wlroots"); const wl = @import("wayland").server.wl; -const log = @import("log.zig"); const util = @import("util.zig"); const Box = @import("Box.zig"); @@ -35,6 +34,8 @@ const ViewStack = @import("view_stack.zig").ViewStack; const XdgToplevel = @import("XdgToplevel.zig"); const XwaylandView = if (build_options.xwayland) @import("XwaylandView.zig") else @import("VoidView.zig"); +const log = std.log.scoped(.view); + pub const Constraints = struct { min_width: u32, max_width: u32, @@ -441,13 +442,13 @@ pub fn map(self: *Self) void { self.pending.target_opacity = self.output.root.server.config.opacity.unfocused; - log.debug(.server, "view '{}' mapped", .{self.getTitle()}); + log.debug("view '{}' mapped", .{self.getTitle()}); if (self.foreign_toplevel_handle == null) { self.foreign_toplevel_handle = wlr.ForeignToplevelHandleV1.create( root.server.foreign_toplevel_manager, ) catch { - log.crit(.server, "out of memory", .{}); + log.crit("out of memory", .{}); self.surface.?.resource.getClient().postNoMemory(); return; }; @@ -482,7 +483,7 @@ pub fn map(self: *Self) void { pub fn unmap(self: *Self) void { const root = self.output.root; - log.debug(.server, "view '{}' unmapped", .{self.getTitle()}); + log.debug("view '{}' unmapped", .{self.getTitle()}); self.destroying = true; @@ -553,7 +554,7 @@ fn killOpacityTimer(self: *Self) void { fn armOpacityTimer(self: *Self) void { const delta_t = self.output.root.server.config.opacity.delta_t; self.opacity_timer.?.timerUpdate(delta_t) catch |err| { - log.err(.view, "failed to update opacity timer: {}", .{err}); + log.err("failed to update opacity timer: {}", .{err}); self.killOpacityTimer(); }; } @@ -572,7 +573,7 @@ fn handleOpacityTimer(self: *Self) callconv(.C) c_int { fn attachOpacityTimer(self: *Self) void { const event_loop = self.output.root.server.wl_server.getEventLoop(); self.opacity_timer = event_loop.addTimer(*Self, handleOpacityTimer, self) catch { - log.err(.view, "failed to create opacity timer for view '{}'", .{self.getTitle()}); + log.err("failed to create opacity timer for view '{}'", .{self.getTitle()}); return; }; self.armOpacityTimer(); diff --git a/river/XdgPopup.zig b/river/XdgPopup.zig index 3b0b0fc..02a5c94 100644 --- a/river/XdgPopup.zig +++ b/river/XdgPopup.zig @@ -21,12 +21,13 @@ const std = @import("std"); const wlr = @import("wlroots"); const wl = @import("wayland").server.wl; -const log = @import("log.zig"); const util = @import("util.zig"); const Box = @import("Box.zig"); const Output = @import("Output.zig"); +const log = std.log.scoped(.server); + /// The output this popup is displayed on. output: *Output, @@ -76,7 +77,7 @@ fn handleNewPopup(listener: *wl.Listener(*wlr.XdgPopup), wlr_xdg_popup: *wlr.Xdg // This will free itself on destroy const xdg_popup = util.gpa.create(Self) catch { wlr_xdg_popup.resource.postNoMemory(); - log.crit(.server, "out of memory", .{}); + log.crit("out of memory", .{}); return; }; xdg_popup.init(self.output, self.parent_box, wlr_xdg_popup); diff --git a/river/XdgToplevel.zig b/river/XdgToplevel.zig index 63f6c09..f80e480 100644 --- a/river/XdgToplevel.zig +++ b/river/XdgToplevel.zig @@ -21,7 +21,6 @@ const std = @import("std"); const wlr = @import("wlroots"); const wl = @import("wayland").server.wl; -const log = @import("log.zig"); const util = @import("util.zig"); const Box = @import("Box.zig"); @@ -30,6 +29,8 @@ const View = @import("View.zig"); const ViewStack = @import("view_stack.zig").ViewStack; const XdgPopup = @import("XdgPopup.zig"); +const log = std.log.scoped(.xdg_shell); + /// The view this xdg toplevel implements view: *View, @@ -257,7 +258,7 @@ fn handleCommit(listener: *wl.Listener(*wlr.Surface), surface: *wlr.Surface) voi } else { // TODO: handle unexpected change in dimensions if (!std.meta.eql(view.surface_box, new_box)) - log.err(.xdg_shell, "view changed size unexpectedly", .{}); + log.err("view changed size unexpectedly", .{}); view.surface_box = new_box; } } diff --git a/river/log.zig b/river/log.zig deleted file mode 100644 index 80fb266..0000000 --- a/river/log.zig +++ /dev/null @@ -1,154 +0,0 @@ -// This file is part of river, a dynamic tiling wayland compositor. -// -// Copyright 2020 The River Developers -// -// This program is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with this program. If not, see . - -const std = @import("std"); - -pub const Level = enum { - /// Emergency: a condition that cannot be handled, usually followed by a - /// panic. - emerg, - /// Alert: a condition that should be corrected immediately (e.g. database - /// corruption). - alert, - /// Critical: A bug has been detected or something has gone wrong and it - /// will have an effect on the operation of the program. - crit, - /// Error: A bug has been detected or something has gone wrong but it is - /// recoverable. - err, - /// Warning: it is uncertain if something has gone wrong or not, but the - /// circumstances would be worth investigating. - warn, - /// Notice: non-error but significant conditions. - notice, - /// Informational: general messages about the state of the program. - info, - /// Debug: messages only useful for debugging. - debug, -}; - -/// The default log level is based on build mode. Note that in ReleaseSmall -/// builds the default level is emerg but no messages will be stored/logged -/// to save space. -pub var level: Level = switch (std.builtin.mode) { - .Debug => .debug, - .ReleaseSafe => .notice, - .ReleaseFast => .err, - .ReleaseSmall => .emerg, -}; - -fn log( - comptime message_level: Level, - comptime scope: @TypeOf(.foobar), - comptime format: []const u8, - args: anytype, -) void { - if (@enumToInt(message_level) <= @enumToInt(level)) { - // Don't store/log messages in release small mode to save space - if (std.builtin.mode != .ReleaseSmall) { - const stderr = std.io.getStdErr().writer(); - stderr.print(@tagName(message_level) ++ ": (" ++ @tagName(scope) ++ ") " ++ - format ++ "\n", args) catch return; - } - } -} - -/// Log an emergency message to stderr. This log level is intended to be used -/// for conditions that cannot be handled and is usually followed by a panic. -pub fn emerg( - comptime scope: @TypeOf(.foobar), - comptime format: []const u8, - args: anytype, -) void { - @setCold(true); - log(.emerg, scope, format, args); -} - -/// Log an alert message to stderr. This log level is intended to be used for -/// conditions that should be corrected immediately (e.g. database corruption). -pub fn alert( - comptime scope: @TypeOf(.foobar), - comptime format: []const u8, - args: anytype, -) void { - @setCold(true); - log(.alert, scope, format, args); -} - -/// Log a critical message to stderr. This log level is intended to be used -/// when a bug has been detected or something has gone wrong and it will have -/// an effect on the operation of the program. -pub fn crit( - comptime scope: @TypeOf(.foobar), - comptime format: []const u8, - args: anytype, -) void { - @setCold(true); - log(.crit, scope, format, args); -} - -/// Log an error message to stderr. This log level is intended to be used when -/// a bug has been detected or something has gone wrong but it is recoverable. -pub fn err( - comptime scope: @TypeOf(.foobar), - comptime format: []const u8, - args: anytype, -) void { - @setCold(true); - log(.err, scope, format, args); -} - -/// Log a warning message to stderr. This log level is intended to be used if -/// it is uncertain whether something has gone wrong or not, but the -/// circumstances would be worth investigating. -pub fn warn( - comptime scope: @TypeOf(.foobar), - comptime format: []const u8, - args: anytype, -) void { - log(.warn, scope, format, args); -} - -/// Log a notice message to stderr. This log level is intended to be used for -/// non-error but significant conditions. -pub fn notice( - comptime scope: @TypeOf(.foobar), - comptime format: []const u8, - args: anytype, -) void { - log(.notice, scope, format, args); -} - -/// Log an info message to stderr. This log level is intended to be used for -/// general messages about the state of the program. -pub fn info( - comptime scope: @TypeOf(.foobar), - comptime format: []const u8, - args: anytype, -) void { - log(.info, scope, format, args); -} - -/// Log a debug message to stderr. This log level is intended to be used for -/// messages which are only useful for debugging. -pub fn debug( - comptime scope: @TypeOf(.foobar), - comptime format: []const u8, - args: anytype, -) void { - log(.debug, scope, format, args); -} diff --git a/river/main.zig b/river/main.zig index 635e30e..803cd7b 100644 --- a/river/main.zig +++ b/river/main.zig @@ -21,11 +21,19 @@ const wlr = @import("wlroots"); const build_options = @import("build_options"); const c = @import("c.zig"); -const log = @import("log.zig"); const util = @import("util.zig"); const Server = @import("Server.zig"); +const log_server = std.log.scoped(.server); + +pub var level: std.log.Level = switch (std.builtin.mode) { + .Debug => .debug, + .ReleaseSafe => .notice, + .ReleaseFast => .err, + .ReleaseSmall => .emerg, +}; + const usage: []const u8 = \\Usage: river [options] \\ @@ -60,6 +68,22 @@ fn getStartupCommand() std.fmt.AllocPrintError!?[:0]const u8 { return null; } +pub fn log( + comptime message_level: std.log.Level, + comptime scope: @TypeOf(.foobar), + comptime format: []const u8, + args: anytype, +) void { + if (@enumToInt(message_level) <= @enumToInt(level)) { + // Don't store/log messages in release small mode to save space + if (std.builtin.mode != .ReleaseSmall) { + const stderr = std.io.getStdErr().writer(); + stderr.print(@tagName(message_level) ++ ": (" ++ @tagName(scope) ++ ") " ++ + format ++ "\n", args) catch return; + } + } +} + pub fn main() anyerror!void { var startup_command: ?[:0]const u8 = null; { @@ -82,9 +106,9 @@ pub fn main() anyerror!void { } } else if (std.mem.eql(u8, arg, "-l")) { if (it.nextPosix()) |level_str| { - const level = std.fmt.parseInt(u3, level_str, 10) catch + const log_level = std.fmt.parseInt(u3, level_str, 10) catch printErrorExit("Error: invalid log level '{}'", .{level_str}); - log.level = @intToEnum(log.Level, level); + level = @intToEnum(std.log.Level, log_level); } else { printErrorExit("Error: flag '-l' requires exactly one argument", .{}); } @@ -96,23 +120,23 @@ pub fn main() anyerror!void { } } - wlr.log.init(switch (log.level) { + wlr.log.init(switch (level) { .debug => .debug, .notice, .info => .info, .warn, .err, .crit, .alert, .emerg => .err, }); - log.info(.server, "initializing", .{}); + log_server.info("initializing", .{}); if (startup_command == null) { if (try getStartupCommand()) |path| { startup_command = path; - log.info(.server, "Using default startup command path: {}", .{path}); + log_server.info("Using default startup command path: {}", .{path}); } else { - log.info(.server, "Starting without startup command", .{}); + log_server.info("Starting without startup command", .{}); } } else { - log.info(.server, "Using custom startup command path: {}", .{startup_command}); + log_server.info("Using custom startup command path: {}", .{startup_command}); } var server: Server = undefined; @@ -132,13 +156,13 @@ pub fn main() anyerror!void { break :blk pid; } else null; defer if (child_pid) |pid| - std.os.kill(pid, std.os.SIGTERM) catch |e| log.err(.server, "failed to kill startup process: {}", .{e}); + std.os.kill(pid, std.os.SIGTERM) catch |e| log_server.err("failed to kill startup process: {}", .{e}); - log.info(.server, "running...", .{}); + log_server.info("running...", .{}); server.wl_server.run(); - log.info(.server, "shutting down", .{}); + log_server.info("shutting down", .{}); } fn printErrorExit(comptime format: []const u8, args: anytype) noreturn { diff --git a/river/render.zig b/river/render.zig index e2b2097..1878c6b 100644 --- a/river/render.zig +++ b/river/render.zig @@ -22,7 +22,6 @@ const wlr = @import("wlroots"); const wl = @import("wayland").server.wl; const pixman = @import("pixman"); -const log = @import("log.zig"); const util = @import("util.zig"); const Box = @import("Box.zig"); @@ -32,6 +31,8 @@ const Server = @import("Server.zig"); const View = @import("View.zig"); const ViewStack = @import("view_stack.zig").ViewStack; +const log = std.log.scoped(.render); + const SurfaceRenderData = struct { output: *const Output, @@ -143,7 +144,7 @@ pub fn renderOutput(output: *Output) void { // TODO: handle failure output.wlr_output.commit() catch - log.err(.render, "output commit failed for {}", .{output.wlr_output.name}); + log.err("output commit failed for {}", .{output.wlr_output.name}); } fn renderFilter(view: *View, filter_tags: u32) bool {