Mercurial > prosody-hg
comparison core/loggingmanager.lua @ 7139:2f9088c663c6
loggingmanager: Stringify all arguments to format so we can finally see the *real* error messages
| author | Kim Alvefur <zash@zash.se> |
|---|---|
| date | Thu, 04 Feb 2016 20:45:37 +0100 |
| parents | ae1d53c2f598 |
| children | e5412e685991 |
comparison
equal
deleted
inserted
replaced
| 7138:ae1d53c2f598 | 7139:2f9088c663c6 |
|---|---|
| 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 unpack = table.unpack or unpack; | |
| 18 | 20 |
| 19 local config = require "core.configmanager"; | 21 local config = require "core.configmanager"; |
| 20 local logger = require "util.logger"; | 22 local logger = require "util.logger"; |
| 21 local prosody = prosody; | 23 local prosody = prosody; |
| 22 | 24 |
| 190 | 192 |
| 191 -- Column width for "source" (used by stdout and console) | 193 -- Column width for "source" (used by stdout and console) |
| 192 local sourcewidth = sink_config.source_width; | 194 local sourcewidth = sink_config.source_width; |
| 193 | 195 |
| 194 return function (name, level, message, ...) | 196 return function (name, level, message, ...) |
| 197 local n = select('#', ...); | |
| 198 if n ~= 0 then | |
| 199 local arg = { ... }; | |
| 200 for i = 1, n do | |
| 201 arg[i] = tostring(arg[i]); | |
| 202 end | |
| 203 message = format(message, unpack(arg, 1, n)); | |
| 204 end | |
| 205 | |
| 195 if sourcewidth then | 206 if sourcewidth then |
| 196 sourcewidth = math_max(#name+2, sourcewidth); | 207 sourcewidth = math_max(#name+2, sourcewidth); |
| 197 name = name .. rep(" ", sourcewidth-#name); | 208 name = name .. rep(" ", sourcewidth-#name); |
| 198 else | 209 else |
| 199 name = name .. "\t"; | 210 name = name .. "\t"; |
| 200 end | 211 end |
| 201 if ... then | 212 write(logfile, timestamps and os_date(timestamps) or "", name, level, "\t", message, "\n"); |
| 202 write(logfile, timestamps and os_date(timestamps) or "", name, level, "\t", format(message, ...), "\n"); | |
| 203 else | |
| 204 write(logfile, timestamps and os_date(timestamps) or "", name, level, "\t", message, "\n"); | |
| 205 end | |
| 206 end | 213 end |
| 207 end | 214 end |
| 208 log_sink_types.file = log_to_file; | 215 log_sink_types.file = log_to_file; |
| 209 | 216 |
| 210 local function log_to_stdout(sink_config) | 217 local function log_to_stdout(sink_config) |
