Comparison

util/logger.lua @ 282:80e7de32b618

Merging my new SASL code with Waqas' adjusted saslauth module.
author Tobias Markmann <tm@ayena.de>
date Sat, 15 Nov 2008 13:47:17 +0100
parent 262:8c73fb2ff4a2
child 360:e918c979ad1a
comparison
equal deleted inserted replaced
280:516f4c901991 282:80e7de32b618
1 1
2 local format = string.format; 2 local format = string.format;
3 local print = print; 3 local print = print;
4 local debug = debug; 4 local debug = debug;
5 local tostring = tostring; 5 local tostring = tostring;
6
7 local getstyle, getstring = require "util.termcolours".getstyle, require "util.termcolours".getstring;
8 local do_pretty_printing = not os.getenv("WINDIR");
9
6 module "logger" 10 module "logger"
11
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
7 20
8 function init(name) 21 function init(name)
9 --name = nil; -- While this line is not commented, will automatically fill in file/line number info 22 --name = nil; -- While this line is not commented, will automatically fill in file/line number info
10 return function (level, message, ...) 23 return function (level, message, ...)
11 if not name then 24 if not name then
12 local inf = debug.getinfo(3, 'Snl'); 25 local inf = debug.getinfo(3, 'Snl');
13 level = level .. ","..tostring(inf.short_src):match("[^/]*$")..":"..inf.currentline; 26 level = level .. ","..tostring(inf.short_src):match("[^/]*$")..":"..inf.currentline;
14 end 27 end
15 if ... then 28 if ... then
16 print(level, format(message, ...)); 29 print(name, getstring(logstyles[level], level), format(message, ...));
17 else 30 else
18 print(level, message); 31 print(name, getstring(logstyles[level], level), message);
19 end 32 end
20 end 33 end
21 end 34 end
22 35
23 return _M; 36 return _M;