# HG changeset patch # User Kim Alvefur # Date 1709461420 -3600 # Node ID 97c9b76867ca3e94a52bfb1ba63693a90337e1a5 # Parent 133b23758cf6023580251c265afd00373d89f480 mod_log_ringbuffer: Detach event handlers on logging reload (thanks Menel) Otherwise the global event handlers accumulate, one added each time logging is reoladed, and each invocation of the signal or event triggers one dump of each created ringbuffer. diff -r 133b23758cf6 -r 97c9b76867ca mod_log_ringbuffer/mod_log_ringbuffer.lua --- a/mod_log_ringbuffer/mod_log_ringbuffer.lua Sat Mar 02 15:11:20 2024 +0100 +++ b/mod_log_ringbuffer/mod_log_ringbuffer.lua Sun Mar 03 11:23:40 2024 +0100 @@ -90,6 +90,8 @@ return write, dump; end +local event_hooks = {}; + local function ringbuffer_log_sink_maker(sink_config) local write, dump = new_buffer(sink_config); @@ -107,8 +109,10 @@ if sink_config.signal then module:hook_global("signal/"..sink_config.signal, handler); + event_hooks[handler] = "signal/"..sink_config.signal; elseif sink_config.event then module:hook_global(sink_config.event, handler); + event_hooks[handler] = sink_config.event; end return function (name, level, message, ...) @@ -117,4 +121,11 @@ end; end +module:hook_global("reopen-log-files", function() + for handler, event_name in pairs(event_hooks) do + module:unhook_object_event(prosody.events, event_name, handler); + event_hooks[handler] = nil; + end +end, 1); + loggingmanager.register_sink_type("ringbuffer", ringbuffer_log_sink_maker);