Diff

core/loggingmanager.lua @ 8235:7d9a2c200736

Merge 0.10->trunk
author Kim Alvefur <zash@zash.se>
date Thu, 14 Sep 2017 02:48:34 +0200
parent 8229:bf6f80f2d971
child 8355:45383e071ded
line wrap: on
line diff
--- a/core/loggingmanager.lua	Wed Sep 13 18:46:39 2017 +0200
+++ b/core/loggingmanager.lua	Thu Sep 14 02:48:34 2017 +0200
@@ -7,7 +7,7 @@
 --
 -- luacheck: globals log prosody.log
 
-local format = string.format;
+local format = require "util.format".format;
 local setmetatable, rawset, pairs, ipairs, type =
 	setmetatable, rawset, pairs, ipairs, type;
 local stdout = io.stdout;
@@ -15,9 +15,6 @@
 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";
@@ -194,23 +191,15 @@
 	-- Column width for "source" (used by stdout and console)
 	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));
+	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");
 		end
-
-		if sourcewidth then
-			sourcewidth = math_max(#name+2, sourcewidth);
-			name = name ..  rep(" ", sourcewidth-#name);
-		else
-			name = name .. "\t";
+	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", message, "\n");
 	end
 end
 log_sink_types.file = log_to_file;