Software /
code /
prosody
Annotate
tests/util/logger.lua @ 7962:4e9b307c30dd
mod_saslauth: Fix typoed variable name [luacheck]
author | Kim Alvefur <zash@zash.se> |
---|---|
date | Mon, 06 Mar 2017 16:05:24 +0100 |
parent | 7921:1821a7cabaa5 |
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 |
7921
1821a7cabaa5
tests/util.logger: Remove use of deprecated module function
Kim Alvefur <zash@zash.se>
parents:
5776
diff
changeset
|
17 local _ENV = nil |
1821a7cabaa5
tests/util.logger: Remove use of deprecated module function
Kim Alvefur <zash@zash.se>
parents:
5776
diff
changeset
|
18 local _M = {} |
272
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 local logstyles = {}; |
c0769fb9af64
Add new logger for tests to use
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
21 |
c0769fb9af64
Add new logger for tests to use
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
22 --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
|
23 if do_pretty_printing then |
c0769fb9af64
Add new logger for tests to use
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
24 logstyles["info"] = getstyle("bold"); |
c0769fb9af64
Add new logger for tests to use
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
25 logstyles["warn"] = getstyle("bold", "yellow"); |
c0769fb9af64
Add new logger for tests to use
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
26 logstyles["error"] = getstyle("bold", "red"); |
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 |
7921
1821a7cabaa5
tests/util.logger: Remove use of deprecated module function
Kim Alvefur <zash@zash.se>
parents:
5776
diff
changeset
|
29 function _M.init(name) |
272
c0769fb9af64
Add new logger for tests to use
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
30 --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
|
31 return function (level, message, ...) |
c0769fb9af64
Add new logger for tests to use
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
32 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
|
33 if not name then |
c0769fb9af64
Add new logger for tests to use
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
34 local inf = debug.getinfo(3, 'Snl'); |
c0769fb9af64
Add new logger for tests to use
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
35 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
|
36 end |
3540
bc139431830b
Monster whitespace commit (beware the whitespace monster).
Waqas Hussain <waqas20@gmail.com>
parents:
2923
diff
changeset
|
37 if ... then |
272
c0769fb9af64
Add new logger for tests to use
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
38 print(name, getstring(logstyles[level], level), format(message, ...)); |
c0769fb9af64
Add new logger for tests to use
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
39 else |
c0769fb9af64
Add new logger for tests to use
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
40 print(name, getstring(logstyles[level], level), message); |
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 end |
c0769fb9af64
Add new logger for tests to use
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
44 |
c0769fb9af64
Add new logger for tests to use
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
45 return _M; |