2 -- Copyright (C) 2008 Matthew Wild
3 -- Copyright (C) 2008 Waqas Hussain
5 -- This program is free software; you can redistribute it and/or
6 -- modify it under the terms of the GNU General Public License
7 -- as published by the Free Software Foundation; either version 2
8 -- of the License, or (at your option) any later version.
10 -- This program is distributed in the hope that it will be useful,
11 -- but WITHOUT ANY WARRANTY; without even the implied warranty of
12 -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 -- GNU General Public License for more details.
15 -- You should have received a copy of the GNU General Public License
16 -- along with this program; if not, write to the Free Software
17 -- Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
22 local format, rep = string.format, string.rep;
23 local io_write = io.write;
26 local tostring = tostring;
27 local math_max = math.max;
29 local getstyle, getstring = require "util.termcolours".getstyle, require "util.termcolours".getstring;
30 local do_pretty_printing = not os.getenv("WINDIR");
36 --TODO: This should be done in config, but we don't have proper config yet
37 if do_pretty_printing then
38 logstyles["info"] = getstyle("bold");
39 logstyles["warn"] = getstyle("bold", "yellow");
40 logstyles["error"] = getstyle("bold", "red");
43 local sourcewidth = 20;
46 --name = nil; -- While this line is not commented, will automatically fill in file/line number info
47 sourcewidth = math_max(#name+2, sourcewidth);
48 local namelen = #name;
49 return function (level, message, ...)
51 local inf = debug.getinfo(3, 'Snl');
52 level = level .. ","..tostring(inf.short_src):match("[^/]*$")..":"..inf.currentline;
55 io_write(name, rep(" ", sourcewidth-namelen), getstring(logstyles[level], level), "\t", format(message, ...), "\n");
57 io_write(name, rep(" ", sourcewidth-namelen), getstring(logstyles[level], level), "\t", message, "\n");