aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKim Alvefur <zash@zash.se>2016-02-04 17:49:09 +0100
committerKim Alvefur <zash@zash.se>2016-02-04 17:49:09 +0100
commitc32e03898c2b4cfe16ca932cefc0b532e5c36463 (patch)
tree164e5e1d67bf206a883e478042e80823f8f43915
parent68d6b5e89eca07ccb645d4bf16ed24218072563d (diff)
downloadprosody-c32e03898c2b4cfe16ca932cefc0b532e5c36463.tar.gz
prosody-c32e03898c2b4cfe16ca932cefc0b532e5c36463.zip
loggingmanager: Move logic for adaptive column width into file sink, append tab if disabled (fixes separation between name and level in plain file sinks)
-rw-r--r--core/loggingmanager.lua20
1 files changed, 11 insertions, 9 deletions
diff --git a/core/loggingmanager.lua b/core/loggingmanager.lua
index c4cf4d3a..ee1aa362 100644
--- a/core/loggingmanager.lua
+++ b/core/loggingmanager.lua
@@ -193,10 +193,19 @@ local function log_to_file(sink_config, logfile)
logfile:setvbuf(sink_config.buffer_mode or "line");
end
+ -- Column width for "source" (used by stdout and console)
+ local sourcewidth = sink_config.source_width;
+
return function (name, level, message, ...)
if timestamps then
write(logfile, os_date(timestamps), " ");
end
+ if sourcewidth then
+ sourcewidth = math_max(#name+2, sourcewidth);
+ name = name .. rep(" ", sourcewidth-#name);
+ else
+ name = name .. "\t";
+ end
if ... then
write(logfile, name, level, "\t", format(message, ...), "\n");
else
@@ -206,19 +215,12 @@ local function log_to_file(sink_config, logfile)
end
log_sink_types.file = log_to_file;
--- Column width for "source" (used by stdout and console)
-local sourcewidth = 20;
-
local function log_to_stdout(sink_config)
if not sink_config.timestamps then
sink_config.timestamps = false;
end
- local logtofile = log_to_file(sink_config, stdout);
- return function (name, level, message, ...)
- sourcewidth = math_max(#name+2, sourcewidth);
- name = name .. rep(" ", sourcewidth-#name);
- return logtofile(name, level, message, ...);
- end
+ sink_config.source_width = 20;
+ return log_to_file(sink_config, stdout);
end
log_sink_types.stdout = log_to_stdout;