Comparison

core/loggingmanager.lua @ 7133:ac142f5209d9

loggingmanager: Write out color code, log level and reset code in one call
author Kim Alvefur <zash@zash.se>
date Thu, 04 Feb 2016 17:03:04 +0100
parent 7132:3868d231c2c5
child 7134:b7b6b1d01224
comparison
equal deleted inserted replaced
7132:3868d231c2c5 7133:ac142f5209d9
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 io_open, io_write = io.open, io.write; 13 local io_open, io_write = io.open, io.write;
14 local math_max, rep = math.max, string.rep; 14 local math_max, rep = math.max, string.rep;
15 local os_date = os.date; 15 local os_date = os.date;
16 local getstyle, setstyle = require "util.termcolours".getstyle, require "util.termcolours".setstyle; 16 local getstyle, getstring = require "util.termcolours".getstyle, require "util.termcolours".getstring;
17 17
18 -- COMPAT: This should no longer be needed since the addition of setvbuf calls 18 -- COMPAT: This should no longer be needed since the addition of setvbuf calls
19 if os.getenv("__FLUSH_LOG") then 19 if os.getenv("__FLUSH_LOG") then
20 local io_flush = io.flush; 20 local io_flush = io.flush;
21 local _io_write = io_write; 21 local _io_write = io_write;
233 233
234 if timestamps then 234 if timestamps then
235 io_write(os_date(timestamps), " "); 235 io_write(os_date(timestamps), " ");
236 end 236 end
237 io_write(name, rep(" ", sourcewidth-namelen)); 237 io_write(name, rep(" ", sourcewidth-namelen));
238 setstyle(logstyles[level]); 238 io_write(getstring(logstyles[level], level));
239 io_write(level);
240 setstyle();
241 if ... then 239 if ... then
242 io_write("\t", format(message, ...), "\n"); 240 io_write("\t", format(message, ...), "\n");
243 else 241 else
244 io_write("\t", message, "\n"); 242 io_write("\t", message, "\n");
245 end 243 end