Software /
code /
prosody
Comparison
tests/util/logger.lua @ 272:c0769fb9af64
Add new logger for tests to use
author | Matthew Wild <mwild1@gmail.com> |
---|---|
date | Sat, 15 Nov 2008 19:11:38 +0000 |
child | 1522:569d58d21612 |
comparison
equal
deleted
inserted
replaced
271:396edd2f9d2e | 272:c0769fb9af64 |
---|---|
1 local format = string.format; | |
2 local print = print; | |
3 local debug = debug; | |
4 local tostring = tostring; | |
5 | |
6 local getstyle, getstring = require "util.termcolours".getstyle, require "util.termcolours".getstring; | |
7 local do_pretty_printing = not os.getenv("WINDIR"); | |
8 | |
9 module "logger" | |
10 | |
11 local logstyles = {}; | |
12 | |
13 --TODO: This should be done in config, but we don't have proper config yet | |
14 if do_pretty_printing then | |
15 logstyles["info"] = getstyle("bold"); | |
16 logstyles["warn"] = getstyle("bold", "yellow"); | |
17 logstyles["error"] = getstyle("bold", "red"); | |
18 end | |
19 | |
20 function init(name) | |
21 --name = nil; -- While this line is not commented, will automatically fill in file/line number info | |
22 return function (level, message, ...) | |
23 if level == "debug" or level == "info" then return; end | |
24 if not name then | |
25 local inf = debug.getinfo(3, 'Snl'); | |
26 level = level .. ","..tostring(inf.short_src):match("[^/]*$")..":"..inf.currentline; | |
27 end | |
28 if ... then | |
29 print(name, getstring(logstyles[level], level), format(message, ...)); | |
30 else | |
31 print(name, getstring(logstyles[level], level), message); | |
32 end | |
33 end | |
34 end | |
35 | |
36 return _M; |