comparison util/logger.lua @ 893:cec476fcc19f

Automated merge with http://waqas.ath.cx:8000/
author Matthew Wild <mwild1@gmail.com>
date Sun, 08 Mar 2009 03:38:22 +0000
parents 5758c39285ab
children 2c0b9e3c11c3
comparison
equal deleted inserted replaced
892:2128891180b7 893:cec476fcc19f
11 local pcall = pcall; 11 local pcall = pcall;
12 local debug = debug; 12 local debug = debug;
13 local tostring = tostring; 13 local tostring = tostring;
14 local math_max = math.max; 14 local math_max = math.max;
15 15
16 local config = require "core.configmanager";
17 local log_sources = config.get("*", "core", "log_sources");
18
16 local getstyle, getstring = require "util.termcolours".getstyle, require "util.termcolours".getstring; 19 local getstyle, getstring = require "util.termcolours".getstyle, require "util.termcolours".getstring;
17 local do_pretty_printing = not os.getenv("WINDIR"); 20 local do_pretty_printing = not os.getenv("WINDIR");
21 local find = string.find;
22 local ipairs = ipairs;
18 23
19 module "logger" 24 module "logger"
20 25
21 local logstyles = {}; 26 local logstyles = {};
22 27
30 local sourcewidth = 20; 35 local sourcewidth = 20;
31 36
32 local outfunction = nil; 37 local outfunction = nil;
33 38
34 function init(name) 39 function init(name)
40 if log_sources then
41 local log_this = false;
42 for _, source in ipairs(log_sources) do
43 if find(name, source) then
44 log_this = true;
45 break;
46 end
47 end
48
49 if not log_this then return function () end end
50 end
51
35 --name = nil; -- While this line is not commented, will automatically fill in file/line number info 52 --name = nil; -- While this line is not commented, will automatically fill in file/line number info
36 local namelen = #name; 53 local namelen = #name;
37 return function (level, message, ...) 54 return function (level, message, ...)
38 if outfunction then return outfunction(name, level, message, ...); end 55 if outfunction then return outfunction(name, level, message, ...); end
39 56