Comparison

core/loggingmanager.lua @ 8226:3463d82276de

loggingmanager, mod_posix: Replace the old inconsistent log formatting with the new util.format
author Waqas Hussain <waqas20@gmail.com>
date Sun, 10 Sep 2017 13:05:45 -0400
parent 7949:8acc35b5355a
child 8227:325371632fe6
comparison
equal deleted inserted replaced
8225:70cb72f46a3b 8226:3463d82276de
5 -- This project is MIT/X11 licensed. Please see the 5 -- This project is MIT/X11 licensed. Please see the
6 -- COPYING file in the source package for more information. 6 -- COPYING file in the source package for more information.
7 -- 7 --
8 -- luacheck: globals log prosody.log 8 -- luacheck: globals log prosody.log
9 9
10 local format = string.format; 10 local format = require "util.format";
11 local setmetatable, rawset, pairs, ipairs, type = 11 local setmetatable, rawset, pairs, ipairs, type =
12 setmetatable, rawset, pairs, ipairs, type; 12 setmetatable, rawset, pairs, ipairs, type;
13 local stdout = io.stdout; 13 local stdout = io.stdout;
14 local io_open = io.open; 14 local io_open = io.open;
15 local math_max, rep = math.max, string.rep; 15 local math_max, rep = math.max, string.rep;
193 193
194 -- Column width for "source" (used by stdout and console) 194 -- Column width for "source" (used by stdout and console)
195 local sourcewidth = sink_config.source_width; 195 local sourcewidth = sink_config.source_width;
196 196
197 return function (name, level, message, ...) 197 return function (name, level, message, ...)
198 local n = select('#', ...);
199 if n ~= 0 then
200 local arg = { ... };
201 for i = 1, n do
202 arg[i] = tostring(arg[i]);
203 end
204 message = format(message, unpack(arg, 1, n));
205 end
206
207 if sourcewidth then 198 if sourcewidth then
208 sourcewidth = math_max(#name+2, sourcewidth); 199 sourcewidth = math_max(#name+2, sourcewidth);
209 name = name .. rep(" ", sourcewidth-#name); 200 name = name .. rep(" ", sourcewidth-#name);
210 else 201 else
211 name = name .. "\t"; 202 name = name .. "\t";
212 end 203 end
213 write(logfile, timestamps and os_date(timestamps) or "", name, level, "\t", message, "\n"); 204 write(logfile, timestamps and os_date(timestamps) or "", name, level, "\t", format(message, ...), "\n");
214 end 205 end
215 end 206 end
216 log_sink_types.file = log_to_file; 207 log_sink_types.file = log_to_file;
217 208
218 local function log_to_stdout(sink_config) 209 local function log_to_stdout(sink_config)