comparison mod_audit/mod_audit.lua @ 4935:ae83200fb55f

mod_audit: make the extension of the module API less of a hack Thanks, Zash, for making me look at mod_http.
author Jonas Schäfer <jonas@wielicki.name>
date Tue, 26 Apr 2022 22:42:09 +0200
parents 08dea42a302a
children 4a5837591380
comparison
equal deleted inserted replaced
4934:08dea42a302a 4935:ae83200fb55f
1 module:set_global(); 1 module:set_global();
2 2
3 local time_now = os.time; 3 local time_now = os.time;
4 local st = require "util.stanza"; 4 local st = require "util.stanza";
5 local moduleapi = require "core.moduleapi";
5 6
6 local host_wide_user = "@"; 7 local host_wide_user = "@";
7 8
8 local stores = {}; 9 local stores = {};
9 10
75 else 76 else
76 module:log("debug", "persisted audit event %s as %s", stanza:top_tag(), id); 77 module:log("debug", "persisted audit event %s as %s", stanza:top_tag(), id);
77 end 78 end
78 end 79 end
79 80
80 local module_api = getmetatable(module).__index; 81 function moduleapi.audit(module, user, event_type, extra)
81 82 audit(module.host, user, "mod_" .. module:get_name(), event_type, extra);
82 function module_api:audit(user, event_type, extra)
83 audit(self.host, user, "mod_" .. self:get_name(), event_type, extra);
84 end 83 end
85 84
86 module:hook("audit", audit, 0); 85 module:hook("audit", audit, 0);