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/21 17:49:14 UTC
[1/2] incubator-ariatosca git commit: added markingup
Repository: incubator-ariatosca
Updated Branches:
refs/heads/ARIA-146-Support-colorful-execution-logging 909ccaace -> 1fc9ac756
added markingup
Project: http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/commit/dbcef5fd
Tree: http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/tree/dbcef5fd
Diff: http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/diff/dbcef5fd
Branch: refs/heads/ARIA-146-Support-colorful-execution-logging
Commit: dbcef5fdd2eca1c8dd4c7473846b401fa677d8fa
Parents: 909ccaa
Author: max-orlov <ma...@gigaspaces.com>
Authored: Fri Apr 21 19:04:09 2017 +0300
Committer: max-orlov <ma...@gigaspaces.com>
Committed: Fri Apr 21 19:04:09 2017 +0300
----------------------------------------------------------------------
aria/cli/color.py | 13 ++++++++++---
aria/cli/execution_logging.py | 11 ++++++++++-
2 files changed, 20 insertions(+), 4 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/dbcef5fd/aria/cli/color.py
----------------------------------------------------------------------
diff --git a/aria/cli/color.py b/aria/cli/color.py
index ed71238..a5ed9b7 100644
--- a/aria/cli/color.py
+++ b/aria/cli/color.py
@@ -39,12 +39,19 @@ class StyledString(object):
def __str__(self):
return self._stylized_str
+ def _style_str(self, styling_str=None):
+ str_ = styling_str or StringIO
+ for arg in self._args:
+ str_.write(arg)
+ if styling_str is not None:
+ return str_
+ else:
+ return str_.getvalue()
+
def _apply_style(self):
assert all(self._is_valid(arg) for arg in self._args)
-
styling_str = StringIO()
- for arg in self._args:
- styling_str.write(arg)
+ self._style_str(styling_str)
styling_str.write(self._original_str)
styling_str.write(self.STYLE.RESET_ALL)
self._stylized_str = styling_str.getvalue()
http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/dbcef5fd/aria/cli/execution_logging.py
----------------------------------------------------------------------
diff --git a/aria/cli/execution_logging.py b/aria/cli/execution_logging.py
index 6019b94..f8eec22 100644
--- a/aria/cli/execution_logging.py
+++ b/aria/cli/execution_logging.py
@@ -100,6 +100,13 @@ class _StylizedLogs(object):
def _style(self, msg, level, style_type):
return StyledString(msg, *self._styles[style_type].get(level.lower(), []))
+ def back(self, str_):
+ if 'web_app' not in str_:
+ return str_
+ modified_str = StyledString.BACK.LIGHTYELLOW_EX +\
+ str_.replace(StyledString.STYLE.RESET_ALL,
+ StyledString.STYLE.RESET_ALL + StyledString.BACK.LIGHTYELLOW_EX) + StyledString.STYLE.RESET_ALL
+ return modified_str
stylized_log = _StylizedLogs()
@@ -138,7 +145,9 @@ def _str(item, formats=None):
# message
formatting_kwargs['message'] = stylized_log.message(item.msg, item.level)
- msg.write(formatting['message'].format(**formatting_kwargs))
+ message = formatting['message'].format(**formatting_kwargs)
+ message = stylized_log.back(message)
+ msg.write(message)
# Add the exception and the error msg.
if item.traceback and env.logging.verbosity_level >= logger.MEDIUM_VERBOSE:
[2/2] incubator-ariatosca git commit: added markingup
Posted by mx...@apache.org.
added markingup
Project: http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/commit/1fc9ac75
Tree: http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/tree/1fc9ac75
Diff: http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/diff/1fc9ac75
Branch: refs/heads/ARIA-146-Support-colorful-execution-logging
Commit: 1fc9ac756b39db9d14acc3cd47efcc8549a16039
Parents: dbcef5f
Author: max-orlov <ma...@gigaspaces.com>
Authored: Fri Apr 21 19:48:07 2017 +0300
Committer: max-orlov <ma...@gigaspaces.com>
Committed: Fri Apr 21 20:49:08 2017 +0300
----------------------------------------------------------------------
aria/cli/commands/logs.py | 5 +-
aria/cli/core/aria.py | 9 +++
aria/cli/execution_logging.py | 129 +++++++++++++++++++++----------------
3 files changed, 85 insertions(+), 58 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/1fc9ac75/aria/cli/commands/logs.py
----------------------------------------------------------------------
diff --git a/aria/cli/commands/logs.py b/aria/cli/commands/logs.py
index 79aff07..f52cfc1 100644
--- a/aria/cli/commands/logs.py
+++ b/aria/cli/commands/logs.py
@@ -28,15 +28,18 @@ def logs():
short_help='List execution logs')
@aria.argument('execution-id')
@aria.options.verbose()
+@aria.options.mark_pattern()
@aria.pass_model_storage
@aria.pass_logger
-def list(execution_id, model_storage, logger):
+def list(execution_id, mark_pattern, model_storage, logger):
"""Display logs for an execution
"""
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)
if not any_logs:
logger.info('\tNo logs')
http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/1fc9ac75/aria/cli/core/aria.py
----------------------------------------------------------------------
diff --git a/aria/cli/core/aria.py b/aria/cli/core/aria.py
index ed7c490..6436c3e 100644
--- a/aria/cli/core/aria.py
+++ b/aria/cli/core/aria.py
@@ -425,5 +425,14 @@ class Options(object):
required=required,
help=helptexts.SERVICE_ID)
+ @staticmethod
+ def mark_pattern(default=None):
+ return click.option(
+ '-m',
+ '--mark-pattern',
+ help='pattern this',
+ type=str,
+ default=default
+ )
options = Options()
http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/1fc9ac75/aria/cli/execution_logging.py
----------------------------------------------------------------------
diff --git a/aria/cli/execution_logging.py b/aria/cli/execution_logging.py
index f8eec22..17ea774 100644
--- a/aria/cli/execution_logging.py
+++ b/aria/cli/execution_logging.py
@@ -13,6 +13,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.
import os
+import re
from StringIO import StringIO
from functools import partial
@@ -27,7 +28,7 @@ MESSAGE = 'message'
IMPLEMENTATION = 'implementation'
INPUTS = 'inputs'
TRACEBACK = 'traceback'
-
+MARKER = 'marker'
DEFAULT_FORMATTING = {
logger.NO_VERBOSE: {'message': '{message}'},
@@ -48,7 +49,7 @@ DEFAULT_FORMATTING = {
},
}
-DEFAULT_STYLES = {
+DEFAULT_STYLING = {
LEVEL: {
'info': (StyledString.FORE.LIGHTMAGENTA_EX,),
'debug': (StyledString.FORE.LIGHTMAGENTA_EX, StyledString.STYLE.DIM),
@@ -76,90 +77,104 @@ DEFAULT_STYLES = {
},
TRACEBACK: {
'error': (StyledString.FORE.RED, )
- }
+ },
+
+ MARKER: StyledString.BACK.LIGHTYELLOW_EX
}
class _StylizedLogs(object):
- def __init__(self, styles=None):
- self._styles = styles or DEFAULT_STYLES
+ def __init__(self, formats=None, styles=None):
+ self._formats = formats or DEFAULT_FORMATTING
+ self._styles = styles or DEFAULT_STYLING
+ self._mark_pattern = None
- def set_styles(self, styles):
- self._styles = styles
+ def set(self, styles=None, formats=None, mark_pattern=None):
+ self._styles = styles or DEFAULT_STYLING
+ self._formats = formats or DEFAULT_FORMATTING
+ self._mark_pattern = mark_pattern
- def unset_styles(self, to_defaults=False):
- self._styles = DEFAULT_STYLES if to_defaults else {}
+ 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._style, style_type=item)
+ return partial(self._stilize, style_type=item[1:])
- def level(self, level):
- return self._style(level[0], level, LEVEL)
+ def _level(self, level):
+ return self._stilize(level[0], level, LEVEL)
- def _style(self, msg, level, style_type):
+ def _stilize(self, msg, level, style_type):
return StyledString(msg, *self._styles[style_type].get(level.lower(), []))
- def back(self, str_):
- if 'web_app' not in str_:
+ def _mark(self, str_):
+ # TODO; this needs more work. since colors cause the patten not to match (since its not a continuous string)
+ if self._mark_pattern is None:
return str_
- modified_str = StyledString.BACK.LIGHTYELLOW_EX +\
- str_.replace(StyledString.STYLE.RESET_ALL,
- StyledString.STYLE.RESET_ALL + StyledString.BACK.LIGHTYELLOW_EX) + StyledString.STYLE.RESET_ALL
+ else:
+ regex_pattern = re.compile(self._mark_pattern)
+ if not re.match(regex_pattern, str_):
+ return str_
+ marker = self._styles[MARKER]
+ modified_str = (
+ marker +
+ str_.replace(StyledString.STYLE.RESET_ALL, StyledString.STYLE.RESET_ALL + marker) +
+ StyledString.STYLE.RESET_ALL
+ )
return modified_str
-stylized_log = _StylizedLogs()
+ def __call__(self, item):
+ # If no formats are passed we revert to the default formats (per level)
+ formatting = self._formats.get(env.logging.verbosity_level,
+ DEFAULT_FORMATTING[env.logging.verbosity_level])
+ msg = StringIO()
+ formatting_kwargs = dict(item=item)
+ # level
+ formatting_kwargs['level'] = self._level(item.level)
-def _str(item, formats=None):
- # If no formats are passed we revert to the default formats (per level)
- formats = formats or {}
- formatting = formats.get(env.logging.verbosity_level,
- DEFAULT_FORMATTING[env.logging.verbosity_level])
- msg = StringIO()
- formatting_kwargs = dict(item=item)
+ # implementation
+ if item.task:
+ # operation task
+ implementation = item.task.implementation
+ inputs = dict(i.unwrap() for i in item.task.inputs.values())
+ else:
+ # execution task
+ implementation = item.execution.workflow_name
+ inputs = dict(i.unwrap() for i in item.execution.inputs.values())
- # level
- formatting_kwargs['level'] = stylized_log.level(item.level)
+ formatting_kwargs['implementation'] = self._implementation(implementation, item.level)
+ formatting_kwargs['inputs'] = self._inputs(inputs, item.level)
- # implementation
- if item.task:
- # operation task
- implementation = item.task.implementation
- inputs = dict(i.unwrap() for i in item.task.inputs.values())
- else:
- # execution task
- implementation = item.execution.workflow_name
- inputs = dict(i.unwrap() for i in item.execution.inputs.values())
+ # timestamp
+ if 'timestamp' in formatting:
+ timestamp = item.created_at.strftime(formatting['timestamp'])
+ else:
+ timestamp = item.created_at
+ formatting_kwargs['timestamp'] = self._timestamp(timestamp, item.level)
- formatting_kwargs['implementation'] = stylized_log.implementation(implementation, item.level)
- formatting_kwargs['inputs'] = stylized_log.inputs(inputs, item.level)
+ # message
+ formatting_kwargs['message'] = self._message(item.msg, item.level)
- # timestamp
- if 'timestamp' in formatting:
- timestamp = item.created_at.strftime(formatting['timestamp'])
- else:
- timestamp = item.created_at
- formatting_kwargs['timestamp'] = stylized_log.timestamp(timestamp, item.level)
+ # The message would be marked out if containing the provided pattern
+ msg.write(self._mark(formatting['message'].format(**formatting_kwargs)))
- # message
- formatting_kwargs['message'] = stylized_log.message(item.msg, item.level)
+ # Add the exception and the error msg.
+ if item.traceback and env.logging.verbosity_level >= logger.MEDIUM_VERBOSE:
+ msg.write(os.linesep)
+ for line in item.traceback.splitlines(True):
+ msg.write(self._traceback('\t' + '|' + line, item.level))
- message = formatting['message'].format(**formatting_kwargs)
- message = stylized_log.back(message)
- msg.write(message)
+ return msg.getvalue()
- # Add the exception and the error msg.
- if item.traceback and env.logging.verbosity_level >= logger.MEDIUM_VERBOSE:
- msg.write(os.linesep)
- for line in item.traceback.splitlines(True):
- msg.write(stylized_log.traceback('\t' + '|' + line, item.level))
- return msg.getvalue()
+stylized_log = _StylizedLogs()
def log(item, *args, **kwargs):
- return getattr(env.logging.logger, item.level.lower())(_str(item), *args, **kwargs)
+ return getattr(env.logging.logger, item.level.lower())(stylized_log(item), *args, **kwargs)
def log_list(iterator):