Software / code / prosody
Comparison
core/loggingmanager.lua @ 3765:0731e5432baa
Merge Tobias->trunk
| author | Matthew Wild <mwild1@gmail.com> |
|---|---|
| date | Fri, 17 Dec 2010 13:50:33 +0000 |
| parent | 3750:e076e4bf70bf |
| child | 4117:b42ca82b0ea4 |
comparison
equal
deleted
inserted
replaced
| 3764:323169f229fa | 3765:0731e5432baa |
|---|---|
| 13 local tostring, setmetatable, rawset, pairs, ipairs, type = | 13 local tostring, setmetatable, rawset, pairs, ipairs, type = |
| 14 tostring, setmetatable, rawset, pairs, ipairs, type; | 14 tostring, setmetatable, rawset, pairs, ipairs, type; |
| 15 local io_open, io_write = io.open, io.write; | 15 local io_open, io_write = io.open, io.write; |
| 16 local math_max, rep = math.max, string.rep; | 16 local math_max, rep = math.max, string.rep; |
| 17 local os_date, os_getenv = os.date, os.getenv; | 17 local os_date, os_getenv = os.date, os.getenv; |
| 18 local getstyle, getstring = require "util.termcolours".getstyle, require "util.termcolours".getstring; | 18 local getstyle, setstyle = require "util.termcolours".getstyle, require "util.termcolours".setstyle; |
| 19 | 19 |
| 20 if os.getenv("__FLUSH_LOG") then | 20 if os.getenv("__FLUSH_LOG") then |
| 21 local io_flush = io.flush; | 21 local io_flush = io.flush; |
| 22 local _io_write = io_write; | 22 local _io_write = io_write; |
| 23 io_write = function(...) _io_write(...); io_flush(); end | 23 io_write = function(...) _io_write(...); io_flush(); end |
| 215 end | 215 end |
| 216 end | 216 end |
| 217 end | 217 end |
| 218 | 218 |
| 219 do | 219 do |
| 220 local do_pretty_printing = not os_getenv("WINDIR"); | 220 local do_pretty_printing = true; |
| 221 | 221 |
| 222 local logstyles = {}; | 222 local logstyles = {}; |
| 223 if do_pretty_printing then | 223 if do_pretty_printing then |
| 224 logstyles["info"] = getstyle("bold"); | 224 logstyles["info"] = getstyle("bold"); |
| 225 logstyles["warn"] = getstyle("bold", "yellow"); | 225 logstyles["warn"] = getstyle("bold", "yellow"); |
| 242 local namelen = #name; | 242 local namelen = #name; |
| 243 | 243 |
| 244 if timestamps then | 244 if timestamps then |
| 245 io_write(os_date(timestamps), " "); | 245 io_write(os_date(timestamps), " "); |
| 246 end | 246 end |
| 247 io_write(name, rep(" ", sourcewidth-namelen)); | |
| 248 setstyle(logstyles[level]); | |
| 249 io_write(level); | |
| 250 setstyle(); | |
| 247 if ... then | 251 if ... then |
| 248 io_write(name, rep(" ", sourcewidth-namelen), getstring(logstyles[level], level), "\t", format(message, ...), "\n"); | 252 io_write("\t", format(message, ...), "\n"); |
| 249 else | 253 else |
| 250 io_write(name, rep(" ", sourcewidth-namelen), getstring(logstyles[level], level), "\t", message, "\n"); | 254 io_write("\t", message, "\n"); |
| 251 end | 255 end |
| 252 end | 256 end |
| 253 end | 257 end |
| 254 end | 258 end |
| 255 | 259 |