mod_log_events: No such thing as module.remove_host. Fix this module so it can be loaded/unloaded dynamically and behave (mostly) correctly
authorMatthew Wild <mwild1@gmail.com>
Tue, 22 Dec 2015 17:54:25 +0000
changeset 1999 0e008f36a91c
parent 1998 f263fcf1b0ed
child 2000 86f2881a04ea
mod_log_events: No such thing as module.remove_host. Fix this module so it can be loaded/unloaded dynamically and behave (mostly) correctly
mod_log_events/mod_log_events.lua
--- a/mod_log_events/mod_log_events.lua	Mon Dec 21 12:24:21 2015 +0100
+++ b/mod_log_events/mod_log_events.lua	Tue Dec 22 17:54:25 2015 +0000
@@ -2,12 +2,16 @@
 
 local helpers = require "util.helpers";
 
-helpers.log_events(prosody.events, "global", module._log);
+local function init(module, events, name)
+	helpers.log_events(events, name, module._log);
+
+	function module.unload()
+		helpers.revert_log_events(events);
+	end
+end
+
+init(module, prosody.events, "global");
 
 function module.add_host(module)
-	helpers.log_events(prosody.hosts[module.host].events, module.host, module._log);
+	init(module, prosody.hosts[module.host].events, module.host);
 end
-
-function module.remove_host(module)
-	helpers.revert_log_events(prosody.hosts[module.host].events);
-end