Comparison

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
comparison
equal deleted inserted replaced
8221:4989a625419a 8235:7d9a2c200736
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".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;
16 local os_date = os.date; 16 local os_date = os.date;
17 local getstyle, getstring = require "util.termcolours".getstyle, require "util.termcolours".getstring; 17 local getstyle, getstring = require "util.termcolours".getstyle, require "util.termcolours".getstring;
18 local tostring = tostring;
19 local select = select;
20 local unpack = table.unpack or unpack; --luacheck: ignore 113
21 18
22 local config = require "core.configmanager"; 19 local config = require "core.configmanager";
23 local logger = require "util.logger"; 20 local logger = require "util.logger";
24 local prosody = prosody; 21 local prosody = prosody;
25 22
192 end 189 end
193 190
194 -- Column width for "source" (used by stdout and console) 191 -- Column width for "source" (used by stdout and console)
195 local sourcewidth = sink_config.source_width; 192 local sourcewidth = sink_config.source_width;
196 193
197 return function (name, level, message, ...) 194 if sourcewidth then
198 local n = select('#', ...); 195 return function (name, level, message, ...)
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
208 sourcewidth = math_max(#name+2, sourcewidth); 196 sourcewidth = math_max(#name+2, sourcewidth);
209 name = name .. rep(" ", sourcewidth-#name); 197 write(logfile, timestamps and os_date(timestamps) or "", name, rep(" ", sourcewidth-#name), level, "\t", format(message, ...), "\n");
210 else 198 end
211 name = name .. "\t"; 199 else
212 end 200 return function (name, level, message, ...)
213 write(logfile, timestamps and os_date(timestamps) or "", name, level, "\t", message, "\n"); 201 write(logfile, timestamps and os_date(timestamps) or "", name, "\t", level, "\t", format(message, ...), "\n");
202 end
214 end 203 end
215 end 204 end
216 log_sink_types.file = log_to_file; 205 log_sink_types.file = log_to_file;
217 206
218 local function log_to_stdout(sink_config) 207 local function log_to_stdout(sink_config)