Software /
code /
prosody
Diff
util/logger.lua @ 8553:32438665dc5e
util.logger: New method 'add_simple_sink', logger.add_simple_sink(print) works
author | Matthew Wild <mwild1@gmail.com> |
---|---|
date | Tue, 27 Feb 2018 16:02:25 +0000 |
parent | 7131:ea3eea291321 |
child | 8555:4f0f5b49bb03 |
line wrap: on
line diff
--- a/util/logger.lua Mon Feb 26 18:31:27 2018 +0100 +++ b/util/logger.lua Tue Feb 27 16:02:25 2018 +0000 @@ -67,10 +67,21 @@ 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; };