diff options
author | Matthew Wild <mwild1@gmail.com> | 2018-02-27 16:02:25 +0000 |
---|---|---|
committer | Matthew Wild <mwild1@gmail.com> | 2018-02-27 16:02:25 +0000 |
commit | eabaac8268c2376225553c37a57de6a281379560 (patch) | |
tree | 1f599b55ed017b3e4f1af71fad625af44e10aee6 /util/logger.lua | |
parent | 60e13b6807f25c4d9222723879ae619e9aedd348 (diff) | |
download | prosody-eabaac8268c2376225553c37a57de6a281379560.tar.gz prosody-eabaac8268c2376225553c37a57de6a281379560.zip |
util.logger: New method 'add_simple_sink', logger.add_simple_sink(print) works
Diffstat (limited to 'util/logger.lua')
-rw-r--r-- | util/logger.lua | 11 |
1 files changed, 11 insertions, 0 deletions
diff --git a/util/logger.lua b/util/logger.lua index e72b29bc..ee257868 100644 --- a/util/logger.lua +++ b/util/logger.lua @@ -67,10 +67,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; }; |