Comparison

mod_stanzadebug/mod_stanzadebug.lua @ 2488:590ac12b7671

mod_stanzadebug: Like mod_rawdebug but stanzas instead of the raw bytes
author Kim Alvefur <zash@zash.se>
date Thu, 09 Feb 2017 10:47:24 +0100
parent 2256:mod_rawdebug/mod_rawdebug.lua@c5c583fae25d
comparison
equal deleted inserted replaced
2487:99a025dc4f6b 2488:590ac12b7671
1 module:set_global();
2
3 local tostring = tostring;
4 local filters = require "util.filters";
5
6 local function log_send(t, session)
7 if t and t ~= "" and t ~= " " then
8 session.log("debug", "SEND: %s", tostring(t));
9 end
10 return t;
11 end
12
13 local function log_recv(t, session)
14 if t and t ~= "" and t ~= " " then
15 session.log("debug", "RECV: %s", tostring(t));
16 end
17 return t;
18 end
19
20 local function init_raw_logging(session)
21 filters.add_filter(session, "stanzas/in", log_recv, -10000);
22 filters.add_filter(session, "stanzas/out", log_send, 10000);
23 end
24
25 filters.add_filter_hook(init_raw_logging);
26
27 function module.unload() -- luacheck: ignore
28 filters.remove_filter_hook(init_raw_logging);
29 end