Software / code / prosody
Annotate
util/logger.lua @ 360:e918c979ad1a
Remove or comment useless prints, or change them to log()
| author | Matthew Wild <mwild1@gmail.com> |
|---|---|
| date | Thu, 20 Nov 2008 03:00:43 +0000 |
| parent | 262:8c73fb2ff4a2 |
| child | 437:c1a720db2157 |
| rev | line source |
|---|---|
| 30 | 1 |
| 2 local format = string.format; | |
| 3 local print = print; | |
| 4 local debug = debug; | |
| 5 local tostring = tostring; | |
| 262 | 6 |
| 7 local getstyle, getstring = require "util.termcolours".getstyle, require "util.termcolours".getstring; | |
| 8 local do_pretty_printing = not os.getenv("WINDIR"); | |
| 9 | |
| 30 | 10 module "logger" |
| 11 | |
| 262 | 12 local logstyles = {}; |
| 13 | |
| 14 --TODO: This should be done in config, but we don't have proper config yet | |
| 15 if do_pretty_printing then | |
| 16 logstyles["info"] = getstyle("bold"); | |
| 17 logstyles["warn"] = getstyle("bold", "yellow"); | |
| 18 logstyles["error"] = getstyle("bold", "red"); | |
| 19 end | |
| 20 | |
| 30 | 21 function init(name) |
| 147 | 22 --name = nil; -- While this line is not commented, will automatically fill in file/line number info |
| 30 | 23 return function (level, message, ...) |
| 24 if not name then | |
|
53
14ea0fe6ca86
Session destruction fixes, some debugging code while we fix the rest. Also change logger to be more useful.
Matthew Wild <mwild1@gmail.com>
parents:
30
diff
changeset
|
25 local inf = debug.getinfo(3, 'Snl'); |
| 30 | 26 level = level .. ","..tostring(inf.short_src):match("[^/]*$")..":"..inf.currentline; |
| 27 end | |
| 28 if ... then | |
| 262 | 29 print(name, getstring(logstyles[level], level), format(message, ...)); |
| 30 | 30 else |
| 262 | 31 print(name, getstring(logstyles[level], level), message); |
| 30 | 32 end |
| 33 end | |
| 34 end | |
| 35 | |
|
360
e918c979ad1a
Remove or comment useless prints, or change them to log()
Matthew Wild <mwild1@gmail.com>
parents:
262
diff
changeset
|
36 return _M; |