Annotate

tests/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 272:c0769fb9af64
child 1522:569d58d21612
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
272
c0769fb9af64 Add new logger for tests to use
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
1 local format = string.format;
c0769fb9af64 Add new logger for tests to use
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
2 local print = print;
c0769fb9af64 Add new logger for tests to use
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
3 local debug = debug;
c0769fb9af64 Add new logger for tests to use
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
4 local tostring = tostring;
c0769fb9af64 Add new logger for tests to use
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
5
c0769fb9af64 Add new logger for tests to use
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
6 local getstyle, getstring = require "util.termcolours".getstyle, require "util.termcolours".getstring;
c0769fb9af64 Add new logger for tests to use
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
7 local do_pretty_printing = not os.getenv("WINDIR");
c0769fb9af64 Add new logger for tests to use
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
8
c0769fb9af64 Add new logger for tests to use
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
9 module "logger"
c0769fb9af64 Add new logger for tests to use
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
10
c0769fb9af64 Add new logger for tests to use
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
11 local logstyles = {};
c0769fb9af64 Add new logger for tests to use
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
12
c0769fb9af64 Add new logger for tests to use
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
13 --TODO: This should be done in config, but we don't have proper config yet
c0769fb9af64 Add new logger for tests to use
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
14 if do_pretty_printing then
c0769fb9af64 Add new logger for tests to use
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
15 logstyles["info"] = getstyle("bold");
c0769fb9af64 Add new logger for tests to use
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
16 logstyles["warn"] = getstyle("bold", "yellow");
c0769fb9af64 Add new logger for tests to use
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
17 logstyles["error"] = getstyle("bold", "red");
c0769fb9af64 Add new logger for tests to use
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
18 end
c0769fb9af64 Add new logger for tests to use
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
19
c0769fb9af64 Add new logger for tests to use
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
20 function init(name)
c0769fb9af64 Add new logger for tests to use
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
21 --name = nil; -- While this line is not commented, will automatically fill in file/line number info
c0769fb9af64 Add new logger for tests to use
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
22 return function (level, message, ...)
c0769fb9af64 Add new logger for tests to use
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
23 if level == "debug" or level == "info" then return; end
c0769fb9af64 Add new logger for tests to use
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
24 if not name then
c0769fb9af64 Add new logger for tests to use
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
25 local inf = debug.getinfo(3, 'Snl');
c0769fb9af64 Add new logger for tests to use
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
26 level = level .. ","..tostring(inf.short_src):match("[^/]*$")..":"..inf.currentline;
c0769fb9af64 Add new logger for tests to use
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
27 end
c0769fb9af64 Add new logger for tests to use
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
28 if ... then
c0769fb9af64 Add new logger for tests to use
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
29 print(name, getstring(logstyles[level], level), format(message, ...));
c0769fb9af64 Add new logger for tests to use
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
30 else
c0769fb9af64 Add new logger for tests to use
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
31 print(name, getstring(logstyles[level], level), message);
c0769fb9af64 Add new logger for tests to use
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
32 end
c0769fb9af64 Add new logger for tests to use
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
33 end
c0769fb9af64 Add new logger for tests to use
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
34 end
c0769fb9af64 Add new logger for tests to use
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
35
c0769fb9af64 Add new logger for tests to use
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
36 return _M;