From 417846da58c448a45b5aba4e9a2d9d3b674c02dd Mon Sep 17 00:00:00 2001 From: Kim Alvefur Date: Tue, 29 Jun 2021 16:05:35 +0200 Subject: core.loggingmanager: Support passing log messages trough a filter This will be used by the console logger for pretty printing. --- core/loggingmanager.lua | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) (limited to 'core/loggingmanager.lua') diff --git a/core/loggingmanager.lua b/core/loggingmanager.lua index 85a6380b..c5b658c8 100644 --- a/core/loggingmanager.lua +++ b/core/loggingmanager.lua @@ -36,6 +36,8 @@ local log_sink_types = setmetatable({}, { __newindex = function (t, k, v) rawset 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 @@ local function log_to_file(sink_config, logfile) -- 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 -- cgit v1.2.3