Annotate

tests/util/logger.lua @ 6485:4224abbf0fdd

net/server: Handle lack of util.signal correctly
author daurnimator <quae@daurnimator.com>
date Wed, 22 Oct 2014 16:00:40 -0400
parent 5776:bd0ff8ae98a8
child 7921:1821a7cabaa5
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1522
569d58d21612 Add copyright header to those files missing one
Matthew Wild <mwild1@gmail.com>
parents: 272
diff changeset
1 -- Prosody IM
2923
b7049746bd29 Update copyright headers for 2010
Matthew Wild <mwild1@gmail.com>
parents: 1522
diff changeset
2 -- Copyright (C) 2008-2010 Matthew Wild
b7049746bd29 Update copyright headers for 2010
Matthew Wild <mwild1@gmail.com>
parents: 1522
diff changeset
3 -- Copyright (C) 2008-2010 Waqas Hussain
5776
bd0ff8ae98a8 Remove all trailing whitespace
Florian Zeitz <florob@babelmonkeys.de>
parents: 3540
diff changeset
4 --
1522
569d58d21612 Add copyright header to those files missing one
Matthew Wild <mwild1@gmail.com>
parents: 272
diff changeset
5 -- This project is MIT/X11 licensed. Please see the
569d58d21612 Add copyright header to those files missing one
Matthew Wild <mwild1@gmail.com>
parents: 272
diff changeset
6 -- COPYING file in the source package for more information.
569d58d21612 Add copyright header to those files missing one
Matthew Wild <mwild1@gmail.com>
parents: 272
diff changeset
7 --
569d58d21612 Add copyright header to those files missing one
Matthew Wild <mwild1@gmail.com>
parents: 272
diff changeset
8
272
c0769fb9af64 Add new logger for tests to use
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
9 local format = string.format;
c0769fb9af64 Add new logger for tests to use
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
10 local print = print;
c0769fb9af64 Add new logger for tests to use
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
11 local debug = debug;
c0769fb9af64 Add new logger for tests to use
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
12 local tostring = tostring;
c0769fb9af64 Add new logger for tests to use
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
13
c0769fb9af64 Add new logger for tests to use
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
14 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
15 local do_pretty_printing = not os.getenv("WINDIR");
c0769fb9af64 Add new logger for tests to use
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
16
c0769fb9af64 Add new logger for tests to use
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
17 module "logger"
c0769fb9af64 Add new logger for tests to use
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
18
c0769fb9af64 Add new logger for tests to use
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
19 local logstyles = {};
c0769fb9af64 Add new logger for tests to use
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
20
c0769fb9af64 Add new logger for tests to use
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
21 --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
22 if do_pretty_printing then
c0769fb9af64 Add new logger for tests to use
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
23 logstyles["info"] = getstyle("bold");
c0769fb9af64 Add new logger for tests to use
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
24 logstyles["warn"] = getstyle("bold", "yellow");
c0769fb9af64 Add new logger for tests to use
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
25 logstyles["error"] = getstyle("bold", "red");
c0769fb9af64 Add new logger for tests to use
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
26 end
c0769fb9af64 Add new logger for tests to use
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
27
c0769fb9af64 Add new logger for tests to use
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
28 function init(name)
c0769fb9af64 Add new logger for tests to use
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
29 --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
30 return function (level, message, ...)
c0769fb9af64 Add new logger for tests to use
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
31 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
32 if not name then
c0769fb9af64 Add new logger for tests to use
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
33 local inf = debug.getinfo(3, 'Snl');
c0769fb9af64 Add new logger for tests to use
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
34 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
35 end
3540
bc139431830b Monster whitespace commit (beware the whitespace monster).
Waqas Hussain <waqas20@gmail.com>
parents: 2923
diff changeset
36 if ... then
272
c0769fb9af64 Add new logger for tests to use
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
37 print(name, getstring(logstyles[level], level), format(message, ...));
c0769fb9af64 Add new logger for tests to use
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
38 else
c0769fb9af64 Add new logger for tests to use
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
39 print(name, getstring(logstyles[level], level), message);
c0769fb9af64 Add new logger for tests to use
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
40 end
c0769fb9af64 Add new logger for tests to use
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
41 end
c0769fb9af64 Add new logger for tests to use
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
42 end
c0769fb9af64 Add new logger for tests to use
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
43
c0769fb9af64 Add new logger for tests to use
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
44 return _M;