Merging my new SASL code with Waqas' adjusted saslauth module.
[prosody.git] / util / logger.lua
1
2 local format = string.format;
3 local print = print;
4 local debug = debug;
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
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
20
21 function init(name)
22         --name = nil; -- While this line is not commented, will automatically fill in file/line number info
23         return  function (level, message, ...)
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;