core/loggingmanager.lua
changeset 11645 b03053ec6dcf
parent 9931 1460c4966262
child 11647 f534eeee1552
--- a/core/loggingmanager.lua	Sat Nov 07 22:09:46 2020 +0100
+++ b/core/loggingmanager.lua	Tue Jun 29 16:05:35 2021 +0200
@@ -36,6 +36,8 @@
 local get_levels;
 local logging_levels = { "debug", "info", "warn", "error" }
 
+local function id(x) return x end
+
 -- Put a rule into action. Requires that the sink type has already been registered.
 -- This function is called automatically when a new sink type is added [see apply_sink_rules()]
 local function add_rule(sink_config)
@@ -184,15 +186,16 @@
 
 	-- Column width for "source" (used by stdout and console)
 	local sourcewidth = sink_config.source_width;
+	local filter = sink_config.filter or id;
 
 	if sourcewidth then
 		return function (name, level, message, ...)
 			sourcewidth = math_max(#name+2, sourcewidth);
-			write(logfile, timestamps and os_date(timestamps) or "", name, rep(" ", sourcewidth-#name), level, "\t", format(message, ...), "\n");
+			write(logfile, timestamps and os_date(timestamps) or "", name, rep(" ", sourcewidth-#name), level, "\t", filter(format(message, ...)), "\n");
 		end
 	else
 		return function (name, level, message, ...)
-			write(logfile, timestamps and os_date(timestamps) or "", name, "\t", level, "\t", format(message, ...), "\n");
+			write(logfile, timestamps and os_date(timestamps) or "", name, "\t", level, "\t", filter(format(message, ...)), "\n");
 		end
 	end
 end