From 9f34801aba7249016e5471ecdeb1b4823ad9d38e Mon Sep 17 00:00:00 2001 From: Matthew Wild Date: Thu, 17 Mar 2022 10:19:35 +0000 Subject: util.logger: Support for removing individual log sinks without a full reset --- util/logger.lua | 15 +++++++++++++++ 1 file changed, 15 insertions(+) (limited to 'util/logger.lua') diff --git a/util/logger.lua b/util/logger.lua index 20a5cef2..a94a1ee1 100644 --- a/util/logger.lua +++ b/util/logger.lua @@ -10,6 +10,7 @@ local pairs = pairs; local ipairs = ipairs; local require = require; +local t_remove = table.remove; local _ENV = nil; -- luacheck: std none @@ -80,6 +81,19 @@ local function add_simple_sink(simple_sink_function, levels) end end +local function remove_sink(sink_function) + local removed; + for level, sinks in pairs(level_sinks) do + for i = #sinks, 1, -1 do + if sinks[i] == sink_function then + t_remove(sinks, i); + removed = true; + end + end + end + return removed; +end + return { init = init; make_logger = make_logger; @@ -87,4 +101,5 @@ return { add_level_sink = add_level_sink; add_simple_sink = add_simple_sink; new = make_logger; + remove_sink = remove_sink; }; -- cgit v1.2.3