Repository: incubator-ariatosca Updated Branches: refs/heads/ARIA-138-Make-logging-more-informative 661dafa9a -> ce068e41b (forced update)
added load to logs, enables to get the formatted string Project: http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/commit/ce068e41 Tree: http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/tree/ce068e41 Diff: http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/diff/ce068e41 Branch: refs/heads/ARIA-138-Make-logging-more-informative Commit: ce068e41b6903036ae05508ca5ab61911f91bf61 Parents: 9e2b70c Author: max-orlov <[email protected]> Authored: Thu Apr 13 12:00:52 2017 +0300 Committer: max-orlov <[email protected]> Committed: Sun Apr 16 08:55:50 2017 +0300 ---------------------------------------------------------------------- aria/cli/commands/executions.py | 4 +- aria/cli/commands/logs.py | 2 +- aria/cli/execution_logging.py | 82 +++++++++++--------- aria/orchestrator/context/common.py | 2 +- aria/orchestrator/workflows/executor/process.py | 11 ++- 5 files changed, 58 insertions(+), 43 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/ce068e41/aria/cli/commands/executions.py ---------------------------------------------------------------------- diff --git a/aria/cli/commands/executions.py b/aria/cli/commands/executions.py index 4bdc481..bd421d2 100644 --- a/aria/cli/commands/executions.py +++ b/aria/cli/commands/executions.py @@ -146,13 +146,13 @@ def start(workflow_name, try: while execution_thread.is_alive(): for log in log_consumer: - execution_logging.log(log) + execution_logging.load(log).log() except KeyboardInterrupt: _cancel_execution(workflow_runner, execution_thread, logger) for log in log_consumer: - execution_logging.log(log) + execution_logging.load(log).log() # raise any errors from the execution thread (note these are not workflow execution errors) execution_thread.raise_error_if_exists() http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/ce068e41/aria/cli/commands/logs.py ---------------------------------------------------------------------- diff --git a/aria/cli/commands/logs.py b/aria/cli/commands/logs.py index 4d5d4e2..e87ee3b 100644 --- a/aria/cli/commands/logs.py +++ b/aria/cli/commands/logs.py @@ -38,7 +38,7 @@ def list(execution_id, model_storage, logger): any_logs = False for log in log_consumer: - execution_logging.log(log) + execution_logging.load(log).log() any_logs = True if not any_logs: http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/ce068e41/aria/cli/execution_logging.py ---------------------------------------------------------------------- diff --git a/aria/cli/execution_logging.py b/aria/cli/execution_logging.py index 9f83310..2ec5c5e 100644 --- a/aria/cli/execution_logging.py +++ b/aria/cli/execution_logging.py @@ -14,45 +14,57 @@ # limitations under the License. import os +from contextlib import contextmanager from . import logger from .env import env +DEFAULT_FORMATTING = { + logger.NO_VERBOSE: {'main_msg': '{item.msg}'}, + logger.LOW_VERBOSE: { + 'main_msg': '{created_at} | {item.level[0]} | {item.msg}', + 'created_at': '%H:%M:%S' + } +} -def log(item): - formats = { - logger.NO_VERBOSE: {'main_msg': '{item.msg}'}, - logger.LOW_VERBOSE: { - 'main_msg': '{created_at} | {item.level[0]} | {item.msg}', - 'created_at': '%H:%M:%S' - } - } +class _ExecutionLogging(object): + + def __init__(self, item, formats=None): + self._item = item + self._formats = formats or DEFAULT_FORMATTING + + def __repr__(self): + # Only NO_VERBOSE and LOW_VERBOSE are configurable formats. configuring + # the low verbose level should affect any higher level. + formats = self._formats[min(env.logging.verbosity_level, logger.LOW_VERBOSE)] + + kwargs = dict(item=self._item) + if 'created_at' in formats: + kwargs['created_at'] = self._item.created_at.strftime(formats['created_at']) + if 'level' in formats: + kwargs['level'] = formats['level'].format(self._item.level) + if 'msg' in formats: + kwargs['msg'] = formats['msg'].format(self._item.msg) + + if 'actor' in formats and self._item.task: + kwargs['actor'] = formats['actor'].format(self._item.task.actor) + if 'execution' in formats: + kwargs['execution'] = formats['execution'].format(self._item.execution) + + # If no format was supplied just print out the original msg. + msg = formats.get('main_msg', '{item.msg}').format(**kwargs) + + # Add the exception and the error msg. + if self._item.traceback and env.logging.verbosity_level >= logger.MEDIUM_VERBOSE: + msg += os.linesep + '------>' + for line in self._item.traceback.splitlines(True): + msg += '\t' + '|' + line + + return msg + + def log(self, *args, **kwargs): + return getattr(env.logging.logger, self._item.level.lower())(self) + - # Only NO_VERBOSE and LOW_VERBOSE are configurable formats. configuring - # the low verbose level should affect any higher level. - formats = formats[min(env.logging.verbosity_level, logger.LOW_VERBOSE)] - - kwargs = dict(item=item) - if 'created_at' in formats: - kwargs['created_at'] = item.created_at.strftime(formats['created_at']) - if 'level' in formats: - kwargs['level'] = formats['level'].format(item.level) - if 'msg' in formats: - kwargs['msg'] = formats['msg'].format(item.msg) - - if 'actor' in formats and item.task: - kwargs['actor'] = formats['actor'].format(item.task.actor) - if 'execution' in formats: - kwargs['execution'] = formats['execution'].format(item.execution) - - # If no format was supplied just print out the original msg. - msg = formats.get('main_msg', '{item.msg}').format(**kwargs) - - # Add the exception and the error msg. - if item.traceback and env.logging.verbosity_level >= logger.MEDIUM_VERBOSE: - msg += os.linesep + '------>' - for line in item.traceback.splitlines(True): - msg += '\t' + '|' + line - - return getattr(env.logging.logger, item.level.lower())(msg) +load = _ExecutionLogging http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/ce068e41/aria/orchestrator/context/common.py ---------------------------------------------------------------------- diff --git a/aria/orchestrator/context/common.py b/aria/orchestrator/context/common.py index 7097d40..67dffcd 100644 --- a/aria/orchestrator/context/common.py +++ b/aria/orchestrator/context/common.py @@ -73,7 +73,7 @@ class BaseContext(object): def _register_logger(self, level=None, task_id=None): self.logger = self.PrefixedLogger( - logging.getLogger(logger.TASK_LOGGER_NAME), task_id=task_id) + logging.getLogger(aria_logger.TASK_LOGGER_NAME), task_id=task_id) self.logger.setLevel(level or logging.DEBUG) if not self.logger.handlers: self.logger.addHandler(self._get_sqla_handler()) http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/ce068e41/aria/orchestrator/workflows/executor/process.py ---------------------------------------------------------------------- diff --git a/aria/orchestrator/workflows/executor/process.py b/aria/orchestrator/workflows/executor/process.py index a5d3cce..160e776 100644 --- a/aria/orchestrator/workflows/executor/process.py +++ b/aria/orchestrator/workflows/executor/process.py @@ -149,10 +149,10 @@ class ProcessExecutor(base.BaseExecutor): def _create_arguments_dict(self, task): return { 'task_id': task.id, - # 'implementation': task.implementation, - 'implementation': 'aria.orchestrator.execution_plugin.operations.run_script_locally', - # 'operation_inputs': Parameter.unwrap_dict(task.inputs), - 'operation_inputs': dict(script_path=task.implementation), + 'implementation': task.implementation, + # 'implementation': 'aria.orchestrator.execution_plugin.operations.run_script_locally', + 'operation_inputs': Parameter.unwrap_dict(task.inputs), + # 'operation_inputs': dict(script_path=task.implementation), 'port': self._server_port, 'context': task.context.serialization_dict, } @@ -383,11 +383,14 @@ def _main(): implementation = arguments['implementation'] operation_inputs = arguments['operation_inputs'] + import pydevd; pydevd.settrace('localhost', suspend=False) + operation_inputs = dict((k, v.value) for k, v in operation_inputs.items()) context_dict = arguments['context'] # This is required for the instrumentation work properly. # See docstring of `remove_mutable_association_listener` for further details modeling_types.remove_mutable_association_listener() + import pydevd; pydevd.settrace('localhost', suspend=False) with instrumentation.track_changes() as instrument: try: ctx = context_dict['context_cls'].deserialize_from_dict(**context_dict['context'])
