You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@ariatosca.apache.org by mx...@apache.org on 2017/04/24 10:55:23 UTC
[2/9] incubator-ariatosca git commit: added easy pattern
configurability
added easy pattern configurability
Project: http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/commit/f91adbc3
Tree: http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/tree/f91adbc3
Diff: http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/diff/f91adbc3
Branch: refs/heads/ARIA-146-Support-colorful-execution-logging
Commit: f91adbc38971c897960e72fb513fc2f5ba15d0bd
Parents: 87c141e
Author: max-orlov <ma...@gigaspaces.com>
Authored: Sat Apr 22 02:42:48 2017 +0300
Committer: max-orlov <ma...@gigaspaces.com>
Committed: Mon Apr 24 11:47:11 2017 +0300
----------------------------------------------------------------------
aria/cli/commands/executions.py | 8 ++++++--
aria/cli/commands/logs.py | 5 ++---
aria/cli/execution_logging.py | 37 ++++++++++++++++++++----------------
3 files changed, 29 insertions(+), 21 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/f91adbc3/aria/cli/commands/executions.py
----------------------------------------------------------------------
diff --git a/aria/cli/commands/executions.py b/aria/cli/commands/executions.py
index 6a1f02a..3eb53ab 100644
--- a/aria/cli/commands/executions.py
+++ b/aria/cli/commands/executions.py
@@ -109,6 +109,7 @@ def list(service_name,
@aria.options.dry_execution
@aria.options.task_max_attempts()
@aria.options.task_retry_interval()
+@aria.options.mark_pattern()
@aria.options.verbose()
@aria.pass_model_storage
@aria.pass_resource_storage
@@ -120,6 +121,7 @@ def start(workflow_name,
dry,
task_max_attempts,
task_retry_interval,
+ mark_pattern,
model_storage,
resource_storage,
plugin_manager,
@@ -147,7 +149,8 @@ def start(workflow_name,
log_iterator = cli_logger.ModelLogIterator(model_storage, workflow_runner.execution_id)
try:
while execution_thread.is_alive():
- execution_logging.log_list(log_iterator)
+ with execution_logging.format(mark_pattern=mark_pattern):
+ execution_logging.log_list(log_iterator)
execution_thread.join(1)
except KeyboardInterrupt:
@@ -155,7 +158,8 @@ def start(workflow_name,
# It might be the case where some logs were written and the execution was terminated, thus we
# need to drain the remaining logs.
- execution_logging.log_list(log_iterator)
+ with execution_logging.format(mark_pattern=mark_pattern):
+ execution_logging.log_list(log_iterator)
# 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/f91adbc3/aria/cli/commands/logs.py
----------------------------------------------------------------------
diff --git a/aria/cli/commands/logs.py b/aria/cli/commands/logs.py
index f52cfc1..8de4662 100644
--- a/aria/cli/commands/logs.py
+++ b/aria/cli/commands/logs.py
@@ -37,9 +37,8 @@ def list(execution_id, mark_pattern, model_storage, logger):
logger.info('Listing logs for execution id {0}'.format(execution_id))
log_iterator = ModelLogIterator(model_storage, execution_id)
- execution_logging.stylized_log.set(mark_pattern=mark_pattern)
- any_logs = execution_logging.log_list(log_iterator)
- execution_logging.stylized_log.reset(to_defaults=True)
+ with execution_logging.format(mark_pattern=mark_pattern):
+ any_logs = execution_logging.log_list(log_iterator)
if not any_logs:
logger.info('\tNo logs')
http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/f91adbc3/aria/cli/execution_logging.py
----------------------------------------------------------------------
diff --git a/aria/cli/execution_logging.py b/aria/cli/execution_logging.py
index 17ea774..d8f1d59 100644
--- a/aria/cli/execution_logging.py
+++ b/aria/cli/execution_logging.py
@@ -15,6 +15,7 @@
import os
import re
from StringIO import StringIO
+from contextlib import contextmanager
from functools import partial
from .color import StyledString
@@ -85,28 +86,23 @@ DEFAULT_STYLING = {
class _StylizedLogs(object):
- def __init__(self, formats=None, styles=None):
- self._formats = formats or DEFAULT_FORMATTING
- self._styles = styles or DEFAULT_STYLING
+ def __init__(self):
+ self._formats = DEFAULT_FORMATTING
+ self._styles = DEFAULT_STYLING
self._mark_pattern = None
- def set(self, styles=None, formats=None, mark_pattern=None):
- self._styles = styles or DEFAULT_STYLING
- self._formats = formats or DEFAULT_FORMATTING
+ def _push(self, styles=None, formats=None, mark_pattern=None):
+ self._styles = styles or self._styles
+ self._formats = formats or self._formats
self._mark_pattern = mark_pattern
- def reset(self, to_defaults=False):
- self._styles = DEFAULT_STYLING if to_defaults else {}
- self._formats = DEFAULT_FORMATTING if to_defaults else {}
- self._mark_pattern = None
-
def __getattr__(self, item):
- return partial(self._stilize, style_type=item[1:])
+ return partial(self._stylize, style_type=item[1:])
def _level(self, level):
- return self._stilize(level[0], level, LEVEL)
+ return self._stylize(level[0], level, LEVEL)
- def _stilize(self, msg, level, style_type):
+ def _stylize(self, msg, level, style_type):
return StyledString(msg, *self._styles[style_type].get(level.lower(), []))
def _mark(self, str_):
@@ -170,11 +166,20 @@ class _StylizedLogs(object):
return msg.getvalue()
-stylized_log = _StylizedLogs()
+stylize_log = _StylizedLogs()
+
+
+@contextmanager
+def format(styles=None, formats=None, mark_pattern=None):
+ original_styles = stylize_log._styles
+ original_formats = stylize_log._formats
+ stylize_log._push(styles=styles, formats=formats, mark_pattern=mark_pattern)
+ yield
+ stylize_log._push(styles=original_styles, formats=original_formats, mark_pattern=None)
def log(item, *args, **kwargs):
- return getattr(env.logging.logger, item.level.lower())(stylized_log(item), *args, **kwargs)
+ return getattr(env.logging.logger, item.level.lower())(stylize_log(item), *args, **kwargs)
def log_list(iterator):