Software / code / prosody
Comparison
util/logger.lua @ 805:5fbbf34ef1c4
Logging format improvement
| author | Waqas Hussain <waqas20@gmail.com> |
|---|---|
| date | Fri, 13 Feb 2009 19:14:36 +0500 |
| parent | 760:90ce865eebd8 |
| child | 883:0112ae30f399 |
comparison
equal
deleted
inserted
replaced
| 791:a4be1d80775c | 805:5fbbf34ef1c4 |
|---|---|
| 31 | 31 |
| 32 local outfunction = nil; | 32 local outfunction = nil; |
| 33 | 33 |
| 34 function init(name) | 34 function init(name) |
| 35 --name = nil; -- While this line is not commented, will automatically fill in file/line number info | 35 --name = nil; -- While this line is not commented, will automatically fill in file/line number info |
| 36 sourcewidth = math_max(#name+2, sourcewidth); | |
| 37 local namelen = #name; | 36 local namelen = #name; |
| 38 return function (level, message, ...) | 37 return function (level, message, ...) |
| 39 if not name then | |
| 40 local inf = debug.getinfo(3, 'Snl'); | |
| 41 level = level .. ","..tostring(inf.short_src):match("[^/]*$")..":"..inf.currentline; | |
| 42 end | |
| 43 | |
| 44 if outfunction then return outfunction(name, level, message, ...); end | 38 if outfunction then return outfunction(name, level, message, ...); end |
| 45 | 39 |
| 40 sourcewidth = math_max(#name+2, sourcewidth); | |
| 46 if ... then | 41 if ... then |
| 47 io_write(name, rep(" ", sourcewidth-namelen), getstring(logstyles[level], level), "\t", format(message, ...), "\n"); | 42 io_write(name, rep(" ", sourcewidth-namelen), getstring(logstyles[level], level), "\t", format(message, ...), "\n"); |
| 48 else | 43 else |
| 49 io_write(name, rep(" ", sourcewidth-namelen), getstring(logstyles[level], level), "\t", message, "\n"); | 44 io_write(name, rep(" ", sourcewidth-namelen), getstring(logstyles[level], level), "\t", message, "\n"); |
| 50 end | 45 end |