From 8dd1e6636c3f4f4fc042e06268641ff41edd5492 Mon Sep 17 00:00:00 2001 From: Sergei Trofimov Date: Mon, 23 Oct 2017 12:25:10 +0100 Subject: [PATCH] framework: set context for loggers Set context for the loggers of the Runner, the workloads and the installed instruments and processors. Errors/warnings logged by these entities will be automatically added as events. --- wa/framework/execution.py | 5 +++-- wa/framework/instrumentation.py | 3 ++- wa/framework/job.py | 1 + wa/framework/processor.py | 3 ++- 4 files changed, 8 insertions(+), 4 deletions(-) diff --git a/wa/framework/execution.py b/wa/framework/execution.py index 65257f9e..4cf7c950 100644 --- a/wa/framework/execution.py +++ b/wa/framework/execution.py @@ -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 diff --git a/wa/framework/instrumentation.py b/wa/framework/instrumentation.py index 1a8290be..377cb4cc 100644 --- a/wa/framework/instrumentation.py +++ b/wa/framework/instrumentation.py @@ -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) diff --git a/wa/framework/job.py b/wa/framework/job.py index a8fad07b..da30c953 100644 --- a/wa/framework/job.py +++ b/wa/framework/job.py @@ -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) diff --git a/wa/framework/processor.py b/wa/framework/processor.py index aca240ae..2273ba50 100644 --- a/wa/framework/processor.py +++ b/wa/framework/processor.py @@ -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):