From c9b43b5bb9d85f68edded36428fb14f05debf190 Mon Sep 17 00:00:00 2001 From: rebecca Date: Sun, 13 Sep 2026 16:25:56 +0100 Subject: use log more pervasively, changes to discord and xmpp: discord: fix some logic errors, correctly ignore messages in channels that we don't care about xmpp: reformat some of the recving logic, but it's still borken somehow, but olive says she wants to fix it not me --- log.lua | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) (limited to 'log.lua') diff --git a/log.lua b/log.lua index 3d04bfc..550a4bd 100644 --- a/log.lua +++ b/log.lua @@ -2,6 +2,8 @@ local pprint = require 'pprint' local class = require 'r.class' local qw = require 'r.qw' +local levels = qw"debug proto info warn error" + local Log = class() function Log.make(cls, name, level) return setmetatable({ @@ -9,12 +11,14 @@ function Log.make(cls, name, level) level = level or 'info', },cls) end -local levels = qw"debug info warn error" +local colours = {debug="\x1b[38;5;8m",error="\x1b[31m"} function Log.format(self, level, ...) local vals = {} for i=1,select('#',...) do - vals[i] = tostring(select(i,...)) end - return (level == 'error' and '\x1b[31m' or '') - ..os.date"%Y-%m-%d %H:%M:%S%z" + local v = (select(i,...)) + vals[i] = type(v) == 'string' and v or pprint.pformat(v) + end + return (colours[level] or '') + .. os.date"%Y-%m-%d %H:%M:%S%z" .. ' ' .. level .. (" "):rep(5-#level) .. ' [' .. self.name .. '] ' .. table.concat(vals,' ') .. '\x1b[0m' .. '\n' -- cgit v1.2.3