1
0
mirror of https://github.com/ARM-software/workload-automation.git synced 2024-10-06 10:51:13 +01:00

Merge pull request #524 from setrofim/logger-events

Logger events
This commit is contained in:
setrofim 2017-10-23 14:27:36 +01:00 committed by GitHub
commit ccaeb5a142
5 changed files with 31 additions and 4 deletions

View File

@ -286,13 +286,13 @@ class Executor(object):
self.logger.info('Installing instrumentation')
for instrument in config_manager.get_instruments(self.target_manager.target):
instrumentation.install(instrument)
instrumentation.install(instrument, context)
instrumentation.validate()
self.logger.info('Installing result processors')
pm = ProcessorManager()
for proc in config_manager.get_processors():
pm.install(proc)
pm.install(proc, context)
pm.validate()
self.logger.info('Starting run')
@ -342,6 +342,7 @@ class Runner(object):
def __init__(self, context, pm):
self.logger = logging.getLogger('runner')
self.logger.context = context
self.context = context
self.pm = pm
self.output = self.context.output

View File

@ -287,7 +287,7 @@ class ManagedCallback(object):
_callbacks = []
def install(instrument):
def install(instrument, context):
"""
This will look for methods (or any callable members) with specific names
in the instrument and hook them up to the corresponding signals.
@ -328,6 +328,7 @@ def install(instrument):
_callbacks.append(mc)
signal.connect(mc, SIGNAL_MAP[attr_name], priority=priority.value)
instrument.logger.context = context
installed.append(instrument)

View File

@ -57,6 +57,7 @@ class Job(object):
def initialize(self, context):
self.logger.info('Initializing job {} [{}]'.format(self.id, self.iteration))
with signal.wrap('WORKLOAD_INITIALIZED', self, context):
self.workload.logger.context = context
self.workload.initialize(context)
self.set_status(Status.PENDING)
context.update_job_state(self)

View File

@ -33,10 +33,11 @@ class ProcessorManager(object):
self.logger = logging.getLogger('processor')
self.processors = []
def install(self, processor):
def install(self, processor, context):
if not isinstance(processor, ResultProcessor):
processor = self.loader.get_result_processor(processor)
self.logger.debug('Installing {}'.format(processor.name))
processor.logger.context = context
self.processors.append(processor)
def validate(self):

View File

@ -44,6 +44,28 @@ _indent_width = 4
_console_handler = None
class ContextLogger(logging.Logger):
def __init__(self, name, context=None):
super(ContextLogger, self).__init__(name)
self.context = context
def warning(self, message):
if self.context:
self.context.add_event(message)
super(ContextLogger, self).warning(message)
def warn(self, message):
if self.context:
self.context.add_event(message)
super(ContextLogger, self).warn(message)
def error(self, message):
if self.context:
self.context.add_event(message)
super(ContextLogger, self).error(message)
def init(verbosity=logging.INFO, color=True, indent_with=4,
regular_fmt='%(levelname)-8s %(message)s',
verbose_fmt='%(asctime)s %(levelname)-8s %(name)10.10s: %(message)s',
@ -51,6 +73,7 @@ def init(verbosity=logging.INFO, color=True, indent_with=4,
global _indent_width, _console_handler
_indent_width = indent_with
signal.log_error_func = lambda m: log_error(m, signal.logger)
logging.setLoggerClass(ContextLogger)
root_logger = logging.getLogger()
root_logger.setLevel(logging.DEBUG)