diff options
Diffstat (limited to 'util/logger.lua')
-rw-r--r-- | util/logger.lua | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/util/logger.lua b/util/logger.lua index e72b29bc..20a5cef2 100644 --- a/util/logger.lua +++ b/util/logger.lua @@ -8,8 +8,11 @@ -- luacheck: ignore 213/level local pairs = pairs; +local ipairs = ipairs; +local require = require; local _ENV = nil; +-- luacheck: std none local level_sinks = {}; @@ -67,10 +70,21 @@ local function add_level_sink(level, sink_function) end end +local function add_simple_sink(simple_sink_function, levels) + local format = require "util.format".format; + local function sink_function(name, level, msg, ...) + return simple_sink_function(name, level, format(msg, ...)); + end + for _, level in ipairs(levels or {"debug", "info", "warn", "error"}) do + add_level_sink(level, sink_function); + end +end + return { init = init; make_logger = make_logger; reset = reset; add_level_sink = add_level_sink; + add_simple_sink = add_simple_sink; new = make_logger; }; |