aboutsummaryrefslogtreecommitdiffstats
path: root/util/helpers.lua
diff options
context:
space:
mode:
authorMatthew Wild <mwild1@gmail.com>2020-09-03 13:00:43 +0100
committerMatthew Wild <mwild1@gmail.com>2020-09-03 13:00:43 +0100
commita5775893f5aa7d107a08d2c8b797c492b605e630 (patch)
treef590d3e6d7dadeb36e132c5885499ae4cc0bc88f /util/helpers.lua
parentc909bca762b655dd798b9f0f5c937feced7aa655 (diff)
downloadprosody-a5775893f5aa7d107a08d2c8b797c492b605e630.tar.gz
prosody-a5775893f5aa7d107a08d2c8b797c492b605e630.zip
util.helpers: when logging events, log individual handler calls
Diffstat (limited to 'util/helpers.lua')
-rw-r--r--util/helpers.lua15
1 files changed, 15 insertions, 0 deletions
diff --git a/util/helpers.lua b/util/helpers.lua
index 02257ffa..139b62ec 100644
--- a/util/helpers.lua
+++ b/util/helpers.lua
@@ -23,12 +23,27 @@ local function log_events(events, name, logger)
logger("debug", "%s firing event: %s", name, event);
return f(event, ...);
end
+
+ local function event_handler_hook(handler, event_name, event_data)
+ logger("debug", "calling handler for %s: %s", event_name, handler);
+ local ok, ret = pcall(handler, event_data);
+ if not ok then
+ logger("error", "error in event handler %s: %s", handler, ret);
+ error(ret);
+ end
+ if ret ~= nil then
+ logger("debug", "event chain ended for %s by %s with result: %s", event_name, handler, ret);
+ end
+ return ret;
+ end
+ events.set_debug_hook(event_handler_hook);
events[events.fire_event] = f;
return events;
end
local function revert_log_events(events)
events.fire_event, events[events.fire_event] = events[events.fire_event], nil; -- :))
+ events.set_debug_hook(nil);
end
local function log_host_events(host)