From d2fbf3c11fb10c2b76455df2a718a8c8d88bf16d Mon Sep 17 00:00:00 2001 From: Anton Khirnov Date: Thu, 5 Jan 2023 16:14:52 +0100 Subject: utils: add logging functions --- bindings.lua | 1 - rc.lua | 4 ++-- urgent_wgt.lua | 2 +- utils.lua | 16 ++++++++++++++++ workspace.lua | 2 +- 5 files changed, 20 insertions(+), 5 deletions(-) diff --git a/bindings.lua b/bindings.lua index 8e08aee..6cce4de 100644 --- a/bindings.lua +++ b/bindings.lua @@ -18,7 +18,6 @@ function M.create(workspace) function () local s = mouse.screen for o, _ in pairs(s.outputs) do - print('toggling ' .. o) awful.spawn('randr_output_toggle ' .. o) end end), diff --git a/rc.lua b/rc.lua index 47e6cb2..43d5fe3 100644 --- a/rc.lua +++ b/rc.lua @@ -86,9 +86,9 @@ mypromptbox = {} local wsp = workspace.Workspace:new(layouts) awful.screen.connect_for_each_screen(function(s) - print('Setting up screen:') + utils.log('screen', 'Setting up screen %d:', s.index) for k, v in pairs(s.outputs) do - print(k) + utils.log('screen', ' %s', k) end local panel_width = beautiful.xresources.apply_dpi(128, s) diff --git a/urgent_wgt.lua b/urgent_wgt.lua index cce4675..270d836 100644 --- a/urgent_wgt.lua +++ b/urgent_wgt.lua @@ -12,7 +12,7 @@ local function client_get_desk_idx(c) if desk_idx ~= nil and desk_idx >= 0 then return desk_idx else - print('cannot get desk idx: ' .. c.first_tag.name) + utils.warn('UrgentWgt', 'cannot get desk idx: ' .. c.first_tag.name) end end return false diff --git a/utils.lua b/utils.lua index eb698dc..0a8d54f 100644 --- a/utils.lua +++ b/utils.lua @@ -146,4 +146,20 @@ function M.notify_singleton(wsp, id, args) wsp.notify_tbl[id] = naughty.notify(args) end +function M.log(component, msg, ...) + local prefix = string.format('[awesome/%s] ', component) + local str = string.format(msg, ...) + + print(prefix .. str) + + return prefix, str +end + +function M.warn(component, msg, ...) + local prefix, str = M.log(component, msg, ...) + naughty.notify({ preset = naughty.config.presets.critical, + title = prefix, + text = str }) +end + return M diff --git a/workspace.lua b/workspace.lua index 9da5e4a..26e2e47 100644 --- a/workspace.lua +++ b/workspace.lua @@ -113,7 +113,7 @@ function Workspace:view(screen, desktop_idx, page_idx) -- take the topmost free one page_idx = desktop.indices_free:pop() if page_idx == nil then - print("No free pages on desktop") + utils.warn('Workspace', 'No free pages on desktop %d', desktop_idx) return end else -- cgit v1.2.3