Software /
code /
prosody
Comparison
util/helpers.lua @ 11059:ad89e3cc67b6
util.helpers: when logging events, log individual handler calls
author | Matthew Wild <mwild1@gmail.com> |
---|---|
date | Thu, 03 Sep 2020 13:00:43 +0100 |
parent | 8411:a9e8523a5e73 |
child | 12975:d10957394a3c |
comparison
equal
deleted
inserted
replaced
11058:c99afee1c548 | 11059:ad89e3cc67b6 |
---|---|
21 name = name or tostring(events); | 21 name = name or tostring(events); |
22 function events.fire_event(event, ...) | 22 function events.fire_event(event, ...) |
23 logger("debug", "%s firing event: %s", name, event); | 23 logger("debug", "%s firing event: %s", name, event); |
24 return f(event, ...); | 24 return f(event, ...); |
25 end | 25 end |
26 | |
27 local function event_handler_hook(handler, event_name, event_data) | |
28 logger("debug", "calling handler for %s: %s", event_name, handler); | |
29 local ok, ret = pcall(handler, event_data); | |
30 if not ok then | |
31 logger("error", "error in event handler %s: %s", handler, ret); | |
32 error(ret); | |
33 end | |
34 if ret ~= nil then | |
35 logger("debug", "event chain ended for %s by %s with result: %s", event_name, handler, ret); | |
36 end | |
37 return ret; | |
38 end | |
39 events.set_debug_hook(event_handler_hook); | |
26 events[events.fire_event] = f; | 40 events[events.fire_event] = f; |
27 return events; | 41 return events; |
28 end | 42 end |
29 | 43 |
30 local function revert_log_events(events) | 44 local function revert_log_events(events) |
31 events.fire_event, events[events.fire_event] = events[events.fire_event], nil; -- :)) | 45 events.fire_event, events[events.fire_event] = events[events.fire_event], nil; -- :)) |
46 events.set_debug_hook(nil); | |
32 end | 47 end |
33 | 48 |
34 local function log_host_events(host) | 49 local function log_host_events(host) |
35 return log_events(prosody.hosts[host].events, host); | 50 return log_events(prosody.hosts[host].events, host); |
36 end | 51 end |