Software /
code /
prosody
Comparison
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 |
comparison
equal
deleted
inserted
replaced
8552:1fcefc16a55d | 8553:32438665dc5e |
---|---|
65 else | 65 else |
66 level_sinks[level][#level_sinks[level] + 1 ] = sink_function; | 66 level_sinks[level][#level_sinks[level] + 1 ] = sink_function; |
67 end | 67 end |
68 end | 68 end |
69 | 69 |
70 local function add_simple_sink(simple_sink_function, levels) | |
71 local format = require "util.format".format; | |
72 local function sink_function(name, level, msg, ...) | |
73 return simple_sink_function(name, level, format(msg, ...)); | |
74 end | |
75 for _, level in ipairs(levels or {"debug", "info", "warn", "error"}) do | |
76 add_level_sink(level, sink_function); | |
77 end | |
78 end | |
79 | |
70 return { | 80 return { |
71 init = init; | 81 init = init; |
72 make_logger = make_logger; | 82 make_logger = make_logger; |
73 reset = reset; | 83 reset = reset; |
74 add_level_sink = add_level_sink; | 84 add_level_sink = add_level_sink; |
85 add_simple_sink = add_simple_sink; | |
75 new = make_logger; | 86 new = make_logger; |
76 }; | 87 }; |