Changeset

1995:0e008f36a91c

mod_log_events: No such thing as module.remove_host. Fix this module so it can be loaded/unloaded dynamically and behave (mostly) correctly
author Matthew Wild <mwild1@gmail.com>
date Tue, 22 Dec 2015 17:54:25 +0000
parents 1994:f263fcf1b0ed
children 1996:86f2881a04ea
files mod_log_events/mod_log_events.lua
diffstat 1 files changed, 10 insertions(+), 6 deletions(-) [+]
line wrap: on
line diff
--- 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