aboutsummaryrefslogtreecommitdiffstats
path: root/util
diff options
context:
space:
mode:
authorMatthew Wild <mwild1@gmail.com>2018-02-27 16:02:25 +0000
committerMatthew Wild <mwild1@gmail.com>2018-02-27 16:02:25 +0000
commitc8a24f6c64be91d2e0d5078ff4fe647f49c88d83 (patch)
tree1f599b55ed017b3e4f1af71fad625af44e10aee6 /util
parent42eec26103c3030ca4f597d4d10f5af59d5bd909 (diff)
downloadprosody-c8a24f6c64be91d2e0d5078ff4fe647f49c88d83.tar.gz
prosody-c8a24f6c64be91d2e0d5078ff4fe647f49c88d83.zip
util.logger: New method 'add_simple_sink', logger.add_simple_sink(print) works
Diffstat (limited to 'util')
-rw-r--r--util/logger.lua11
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;
};