Commit 7450b19d authored by Swann Perarnau's avatar Swann Perarnau
Browse files

Restore debug filtering using module names

We broke debug filtering during our transition to standard logging. This
patch restore the filter, using the name of the module as the filter
key.

We also ensure that the debug option is correctly propagated to children
processes.

Fix #15
parent 11d4dce5
......@@ -1087,11 +1087,11 @@ class Erebor:
self.start_taktuk_on(child, networkId, options)
self.on_children_startup(dest, network, after_chilren_startup)
debug = ""
if len(self.debug_list) > 0 :
if len(self.debug_list):
debug = "--debug="+(",".join(self.debug_list))
debug += " --debug-level "+self.loglv
if self.logf != "" :
debug += " --debug-file "+self.logf
debug += " --debug-level "+self.loglv
if self.logf != "" :
debug += " --debug-file "+self.logf
# launch the children
name = pwd.getpwuid(os.getuid()).pw_name
command = ""
......
......@@ -30,9 +30,8 @@ def runner(argv, Controler=None):
parser.add_argument(
"-d",
"--debug",
default="erebor,network,isengard,wrapper,unix_socket,bridge,mpi",
help='''Set which parts needs to output debug infos (comma
separated
default='*',
help='''Comma-separated list of modules being debugged.
Goes along with debug-level and debug-file'''
)
parser.add_argument(
......@@ -41,7 +40,7 @@ def runner(argv, Controler=None):
default="CRITICAL",
help='''\
Debug precision level.
To be choosed in the following list :
To be chosen in the following list:
-------------------------------------
NOTSET DEBUG INFO WARNING ERROR CRITICAL
'''
......@@ -122,10 +121,9 @@ def runner(argv, Controler=None):
# Custom operations for parameters
# Transform * to a list of loggers
if log == "*" :
log = ["erebor", "network", "isengard", "wrapper",
"unix_socket", "bridge", "mpi"]
else :
if log == "*":
log = []
else:
log = log.split(",")
# Parse the host file
......
......@@ -870,9 +870,8 @@ def main():
parser.add_argument(
"-d",
"--debug",
default="erebor,network,isengard,wrapper,unix_socket,bridge,mpi",
help='''Set which parts needs to output debug infos (comma
separated
default="*",
help='''Comma-separated list of modules being debugged.
Goes along with debug-level and debug-file'''
)
parser.add_argument(
......@@ -908,10 +907,9 @@ def main():
# Custom operations for parameters
# Transform * to a list of loggers
if log == "*" :
log = ["erebor", "network", "isengard", "wrapper",
"unix_socket", "bridge", "mpi"]
else :
if log == "*":
log = []
else:
log = log.split(",")
configure_logger(logger, log, loglv, logf)
......
......@@ -67,11 +67,11 @@ class Unix_socket(Thread):
# ask taktuk to launch the bridge program
def launch_bridge(self):
debug = ""
if len(self.debug_list) > 0 :
debug = "--debug "+(",".join(self.debug_list))
debug += " --debug-level "+self.loglv
if self.logf != "" :
debug += " --debug-file "+self.logf
if len(self.debug_list):
debug = "--debug "+(",".join(self.debug_list))
debug += " --debug-level "+self.loglv
if self.logf:
debug += " --debug-file "+self.logf
cmd ='0 exec [ python3 -c \"__requires__ = \'yggdrasil\';import sys;from pkg_resources import load_entry_point;sys.exit(load_entry_point(\'yggdrasil\', \'console_scripts\', \'taktuk-bridge\')());\" --socket '+self.control_adress+" "+debug+" ] "
logger.info(cmd)
self.taktuk.send_command(cmd)
......
import logging
class ModuleFilter(logging.Filter):
"""Logging filter that removes messages if they are not part of a list of
allowed modules."""
def __init__(self, modules):
self.modules = modules
def filter(self, record):
if record.module in self.modules:
return 1
else:
return 0
def configure_logger(logger, log, loglv, logf):
FMT = '%(asctime)s - %(name)s - %(module)s - %(levelname)s - %(message)s'
formatter = logging.Formatter(FMT)
......@@ -12,4 +26,6 @@ def configure_logger(logger, log, loglv, logf):
ch.setFormatter(formatter)
logger.addHandler(ch)
logger.setLevel(loglv)
if log:
logger.addFilter(ModuleFilter(log))
return logger
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment