aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKim Alvefur <zash@zash.se>2021-06-29 16:05:35 +0200
committerKim Alvefur <zash@zash.se>2021-06-29 16:05:35 +0200
commit417846da58c448a45b5aba4e9a2d9d3b674c02dd (patch)
treed496ff5721519a1adfc7f5c2190c1534e51d7b54
parentdb2c51bcae351065eeb31094eed8fa98cd5172f3 (diff)
downloadprosody-417846da58c448a45b5aba4e9a2d9d3b674c02dd.tar.gz
prosody-417846da58c448a45b5aba4e9a2d9d3b674c02dd.zip
core.loggingmanager: Support passing log messages trough a filter
This will be used by the console logger for pretty printing.
-rw-r--r--core/loggingmanager.lua7
1 files changed, 5 insertions, 2 deletions
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