Support to filter logging by source via pattern matching from config file.
authorTobias Markmann <tm@ayena.de>
Sat, 7 Mar 2009 19:33:21 +0000 (20:33 +0100)
committerTobias Markmann <tm@ayena.de>
Sat, 7 Mar 2009 19:33:21 +0000 (20:33 +0100)
util/logger.lua

index 791e222b0f39a93fbeb53454362995421f8499b7..9969f934a507895f979a6ed1aa79f705898bb630 100644 (file)
@@ -13,8 +13,13 @@ local debug = debug;
 local tostring = tostring;
 local math_max = math.max;
 
+local config = require "core.configmanager";
+local log_sources = config.get("*", "core", "log_sources");
+
 local getstyle, getstring = require "util.termcolours".getstyle, require "util.termcolours".getstring;
 local do_pretty_printing = not os.getenv("WINDIR");
+local find = require "string".find;
+local ipairs = ipairs;
 
 module "logger"
 
@@ -32,6 +37,18 @@ local sourcewidth = 20;
 local outfunction = nil;
 
 function init(name)
+       if log_sources then
+               local log_this = false;
+               for _, source in ipairs(log_sources) do
+                       if find(name, source) then 
+                               log_this = true
+                               break
+                       end
+               end
+               
+               if not log_this then return function () end end
+       end
+       
        --name = nil; -- While this line is not commented, will automatically fill in file/line number info
        local namelen = #name;
        return  function (level, message, ...)