Changeset

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
parents 8552:1fcefc16a55d
children 8554:12a68e0d0ecf
files util/logger.lua
diffstat 1 files changed, 11 insertions(+), 0 deletions(-) [+]
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;
 };