From 79acb207db938b5f8c6384fa36a0d2467f763b9a Mon Sep 17 00:00:00 2001 From: Waqas Hussain Date: Sun, 10 Sep 2017 13:05:45 -0400 Subject: loggingmanager, mod_posix: Replace the old inconsistent log formatting with the new util.format --- core/loggingmanager.lua | 13 ++----------- 1 file changed, 2 insertions(+), 11 deletions(-) (limited to 'core/loggingmanager.lua') diff --git a/core/loggingmanager.lua b/core/loggingmanager.lua index 14305588..1b888a7e 100644 --- a/core/loggingmanager.lua +++ b/core/loggingmanager.lua @@ -7,7 +7,7 @@ -- -- luacheck: globals log prosody.log -local format = string.format; +local format = require "util.format"; local setmetatable, rawset, pairs, ipairs, type = setmetatable, rawset, pairs, ipairs, type; local stdout = io.stdout; @@ -195,22 +195,13 @@ local function log_to_file(sink_config, logfile) local sourcewidth = sink_config.source_width; return function (name, level, message, ...) - local n = select('#', ...); - if n ~= 0 then - local arg = { ... }; - for i = 1, n do - arg[i] = tostring(arg[i]); - end - message = format(message, unpack(arg, 1, n)); - end - if sourcewidth then sourcewidth = math_max(#name+2, sourcewidth); name = name .. rep(" ", sourcewidth-#name); else name = name .. "\t"; end - write(logfile, timestamps and os_date(timestamps) or "", name, level, "\t", message, "\n"); + write(logfile, timestamps and os_date(timestamps) or "", name, level, "\t", format(message, ...), "\n"); end end log_sink_types.file = log_to_file; -- cgit v1.2.3 From 0867e29552f4fd7c041f696be1b45a3a78b84cfd Mon Sep 17 00:00:00 2001 From: Waqas Hussain Date: Sun, 10 Sep 2017 13:13:24 -0400 Subject: loggingmanager: Slight cleanup and optimization of file sink --- core/loggingmanager.lua | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) (limited to 'core/loggingmanager.lua') diff --git a/core/loggingmanager.lua b/core/loggingmanager.lua index 1b888a7e..2e9590fe 100644 --- a/core/loggingmanager.lua +++ b/core/loggingmanager.lua @@ -194,14 +194,15 @@ local function log_to_file(sink_config, logfile) -- Column width for "source" (used by stdout and console) local sourcewidth = sink_config.source_width; - return function (name, level, message, ...) - if sourcewidth then + if sourcewidth then + return function (name, level, message, ...) sourcewidth = math_max(#name+2, sourcewidth); - name = name .. rep(" ", sourcewidth-#name); - else - name = name .. "\t"; + write(logfile, timestamps and os_date(timestamps) or "", name, rep(" ", sourcewidth-#name), level, "\t", 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"); end - write(logfile, timestamps and os_date(timestamps) or "", name, level, "\t", format(message, ...), "\n"); end end log_sink_types.file = log_to_file; -- cgit v1.2.3 From f125342f41c0e398749b42d7a202d1d364aded71 Mon Sep 17 00:00:00 2001 From: Kim Alvefur Date: Mon, 11 Sep 2017 19:32:12 +0200 Subject: loggingmanager, mod_posix: Import util.format correctly (fixes #985) --- core/loggingmanager.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'core/loggingmanager.lua') diff --git a/core/loggingmanager.lua b/core/loggingmanager.lua index 2e9590fe..3d469bed 100644 --- a/core/loggingmanager.lua +++ b/core/loggingmanager.lua @@ -7,7 +7,7 @@ -- -- luacheck: globals log prosody.log -local format = require "util.format"; +local format = require "util.format".format; local setmetatable, rawset, pairs, ipairs, type = setmetatable, rawset, pairs, ipairs, type; local stdout = io.stdout; -- cgit v1.2.3 From 437e9ef7faf96068d68a836386e14435a18252f7 Mon Sep 17 00:00:00 2001 From: Kim Alvefur Date: Mon, 11 Sep 2017 19:32:51 +0200 Subject: core.loggingmanager: Remove now unused locals [luacheck] --- core/loggingmanager.lua | 3 --- 1 file changed, 3 deletions(-) (limited to 'core/loggingmanager.lua') diff --git a/core/loggingmanager.lua b/core/loggingmanager.lua index 3d469bed..6dc1c1d1 100644 --- a/core/loggingmanager.lua +++ b/core/loggingmanager.lua @@ -15,9 +15,6 @@ local io_open = io.open; local math_max, rep = math.max, string.rep; local os_date = os.date; local getstyle, getstring = require "util.termcolours".getstyle, require "util.termcolours".getstring; -local tostring = tostring; -local select = select; -local unpack = table.unpack or unpack; --luacheck: ignore 113 local config = require "core.configmanager"; local logger = require "util.logger"; -- cgit v1.2.3