Software /
code /
prosody
Comparison
core/loggingmanager.lua @ 7135:0b614b7333f1
loggingmanager: Move logic for adaptive column width into file sink, append tab if disabled (fixes separation between name and level in plain file sinks)
author | Kim Alvefur <zash@zash.se> |
---|---|
date | Thu, 04 Feb 2016 17:49:09 +0100 |
parent | 7134:b7b6b1d01224 |
child | 7136:6c3a33e54399 |
comparison
equal
deleted
inserted
replaced
7134:b7b6b1d01224 | 7135:0b614b7333f1 |
---|---|
191 | 191 |
192 if sink_config.buffer_mode ~= false then | 192 if sink_config.buffer_mode ~= false then |
193 logfile:setvbuf(sink_config.buffer_mode or "line"); | 193 logfile:setvbuf(sink_config.buffer_mode or "line"); |
194 end | 194 end |
195 | 195 |
196 -- Column width for "source" (used by stdout and console) | |
197 local sourcewidth = sink_config.source_width; | |
198 | |
196 return function (name, level, message, ...) | 199 return function (name, level, message, ...) |
197 if timestamps then | 200 if timestamps then |
198 write(logfile, os_date(timestamps), " "); | 201 write(logfile, os_date(timestamps), " "); |
202 end | |
203 if sourcewidth then | |
204 sourcewidth = math_max(#name+2, sourcewidth); | |
205 name = name .. rep(" ", sourcewidth-#name); | |
206 else | |
207 name = name .. "\t"; | |
199 end | 208 end |
200 if ... then | 209 if ... then |
201 write(logfile, name, level, "\t", format(message, ...), "\n"); | 210 write(logfile, name, level, "\t", format(message, ...), "\n"); |
202 else | 211 else |
203 write(logfile, name, level, "\t", message, "\n"); | 212 write(logfile, name, level, "\t", message, "\n"); |
204 end | 213 end |
205 end | 214 end |
206 end | 215 end |
207 log_sink_types.file = log_to_file; | 216 log_sink_types.file = log_to_file; |
208 | 217 |
209 -- Column width for "source" (used by stdout and console) | |
210 local sourcewidth = 20; | |
211 | |
212 local function log_to_stdout(sink_config) | 218 local function log_to_stdout(sink_config) |
213 if not sink_config.timestamps then | 219 if not sink_config.timestamps then |
214 sink_config.timestamps = false; | 220 sink_config.timestamps = false; |
215 end | 221 end |
216 local logtofile = log_to_file(sink_config, stdout); | 222 sink_config.source_width = 20; |
217 return function (name, level, message, ...) | 223 return log_to_file(sink_config, stdout); |
218 sourcewidth = math_max(#name+2, sourcewidth); | |
219 name = name .. rep(" ", sourcewidth-#name); | |
220 return logtofile(name, level, message, ...); | |
221 end | |
222 end | 224 end |
223 log_sink_types.stdout = log_to_stdout; | 225 log_sink_types.stdout = log_to_stdout; |
224 | 226 |
225 local do_pretty_printing = true; | 227 local do_pretty_printing = true; |
226 | 228 |