From 8a253c1cc93aa94a1a3782954035720f45e8b96c Mon Sep 17 00:00:00 2001 From: Tobias Markmann Date: Sat, 7 Mar 2009 20:33:21 +0100 Subject: Support to filter logging by source via pattern matching from config file. --- util/logger.lua | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) (limited to 'util/logger.lua') diff --git a/util/logger.lua b/util/logger.lua index 791e222b..9969f934 100644 --- a/util/logger.lua +++ b/util/logger.lua @@ -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, ...) -- cgit v1.2.3 From b657bdb211b25227ea37c9db458ec960b060c0d9 Mon Sep 17 00:00:00 2001 From: Matthew Wild Date: Sat, 7 Mar 2009 19:40:00 +0000 Subject: util.logger: Small code tidying :) --- util/logger.lua | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'util/logger.lua') diff --git a/util/logger.lua b/util/logger.lua index 9969f934..2c8eea30 100644 --- a/util/logger.lua +++ b/util/logger.lua @@ -18,7 +18,7 @@ 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 find = string.find; local ipairs = ipairs; module "logger" @@ -41,8 +41,8 @@ function init(name) local log_this = false; for _, source in ipairs(log_sources) do if find(name, source) then - log_this = true - break + log_this = true; + break; end end -- cgit v1.2.3