From: Tobias Ulmer Date: Wed, 6 Nov 2013 18:01:41 +0000 (+0100) Subject: Extend trace module to allow for filtering X-Git-Tag: e2factory-2.3.15rc1~405 X-Git-Url: https://git.e2factory.org/?a=commitdiff_plain;h=917c2fe9d9552d47b45f99bf33f96c9f62233a73;p=e2factory.git Extend trace module to allow for filtering Attempt to reduce the debug.log noise by filtering the err module warnf/logf calls and others. Signed-off-by: Tobias Ulmer --- diff --git a/generic/e2lib.lua b/generic/e2lib.lua index 66c7d6c..62bdaf1 100644 --- a/generic/e2lib.lua +++ b/generic/e2lib.lua @@ -321,6 +321,7 @@ function e2lib.init() e2lib.log(4, "e2lib.init()") trace.enable() + trace.default_filter() local rc, re = e2lib.signal_reset() if not rc then diff --git a/generic/trace.lua b/generic/trace.lua index 516e53d..511c337 100644 --- a/generic/trace.lua +++ b/generic/trace.lua @@ -22,11 +22,14 @@ local trace = {} local e2lib = require("e2lib") local strict = require("strict") +local module_blacklist = {} +local function_blacklist = {} + --- Function call tracer. Logs all function calls at debug level while active. -- @param event string: type of event -- @param line line number of event (unused) local function tracer(event, line) - local ftbl, module, out, name, value, isbinary, svalue + local ftbl, module, out, name, value, isbinary, svalue, fnbl ftbl = debug.getinfo(2) if ftbl == nil or ftbl.name == nil then @@ -36,13 +39,20 @@ local function tracer(event, line) -- approximate module name, not always accurate but good enough if ftbl.source == nil or ftbl.source == "=[C]" then module = "C." - -- DEBUG: comment this to see all C calls. - return else module = string.match(ftbl.source, "([^/]+%.)lua$") if module == nil then module = "." - -- DEBUG: comment this to see all unknown calls. + end + end + + if module_blacklist[module] then + return + end + + fnbl = function_blacklist[ftbl.name] + if fnbl then + if fnbl[module] then return end end @@ -103,6 +113,41 @@ function trace.disable() debug.sethook() end +--- Exclude entire module from being logged by the tracer. +-- @param module_name Module name. +function trace.filter_module(module_name) + module_name = module_name.."." + module_blacklist[module_name] = true +end + +--- Exclude function in a module from being logged by the tracer. +-- @param module_name Module name. +-- @param function_name Function name. +function trace.filter_function(module_name, function_name) + local fnbl + + module_name = module_name.."." + if not function_blacklist[function_name] then + function_blacklist[function_name] = {} + end + + function_blacklist[function_name][module_name] = true +end + +--- Default filter setup. +function trace.default_filter() + trace.filter_module("C") + trace.filter_module("") + trace.filter_module("err") + trace.filter_function("e2lib", "log") + trace.filter_function("e2lib", "logf") + trace.filter_function("e2lib", "getlog") + trace.filter_function("e2lib", "warnf") + trace.filter_function("e2lib", "(for generator)") + trace.filter_function("eio", "new") + trace.filter_function("eio", "is_eio_object") +end + return strict.lock(trace) -- vim:sw=4:sts=4:et: