Repository: incubator-ariatosca
Updated Branches:
  refs/heads/ARIA-146-Support-colorful-execution-logging 193f3738a -> a82c3c024


even more cleanup


Project: http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/repo
Commit: 
http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/commit/a82c3c02
Tree: http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/tree/a82c3c02
Diff: http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/diff/a82c3c02

Branch: refs/heads/ARIA-146-Support-colorful-execution-logging
Commit: a82c3c024c6e18d615c6439418bb3b317b15103d
Parents: 193f373
Author: max-orlov <[email protected]>
Authored: Wed Apr 26 23:28:57 2017 +0300
Committer: max-orlov <[email protected]>
Committed: Wed Apr 26 23:28:57 2017 +0300

----------------------------------------------------------------------
 aria/cli/color.py             |  6 +++---
 aria/cli/execution_logging.py | 38 +++++++++++++++++++++-----------------
 2 files changed, 24 insertions(+), 20 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/a82c3c02/aria/cli/color.py
----------------------------------------------------------------------
diff --git a/aria/cli/color.py b/aria/cli/color.py
index 7307e8a..44ace8b 100644
--- a/aria/cli/color.py
+++ b/aria/cli/color.py
@@ -52,11 +52,11 @@ class StylizedString(object):
     def format(self, *args, **kwargs):
         self._str = self._str.format(*args, **kwargs)
 
-    def highlight(self, original_value, schema, original_schema, pattern=None):
+    def highlight(self, pattern, schema):
         if pattern is None:
             return
-        for match in set(re.findall(re.compile(pattern), str(original_value))):
-            self.replace(match, schema + match + Color.Style.RESET_ALL + 
original_schema)
+        for match in set(re.findall(re.compile(pattern), self._str)):
+            self.replace(match, schema + match + Color.Style.RESET_ALL + 
self._schema)
 
 
 class Color(object):

http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/a82c3c02/aria/cli/execution_logging.py
----------------------------------------------------------------------
diff --git a/aria/cli/execution_logging.py b/aria/cli/execution_logging.py
index 7aa7b64..5cbf75a 100644
--- a/aria/cli/execution_logging.py
+++ b/aria/cli/execution_logging.py
@@ -158,8 +158,13 @@ def _styles(field_type):
     return env.config.logging.styles[field_type]
 
 
-def _is_styling_enabled():
-    return env.config.logging.styling_enabled
+def _is_styling_enabled(log_item):
+    return (
+        # If styling is enabled
+        env.config.logging.styling_enabled or
+        # with the exception of the final string formatting
+        _end_execution_schema(log_item)
+    )
 
 
 def _get_marker_schema():
@@ -191,24 +196,23 @@ def _stylize(stylized_str, msg, log_item, msg_type, 
mark_pattern=None):
     if not matched_str:
         return stylized_str
 
-    # if Styling was disabled
-    if not _is_styling_enabled():
-        return stylized_str.replace(matched_str, 
matched_str.format(**{msg_type: msg}))
-
-    # If the log is not of a final workflow message, it could be configured 
through the
-    # config file. Thus it should be instantiated from the dict provided.
-    schema = _resolve_schema(msg_type, log_item)
     substring = Color.stylize(matched_str)
-    substring.color(schema or '')
+
     substring.format(**{msg_type: msg})
-    substring.highlight(msg, _get_marker_schema(), schema, mark_pattern)
+    if _is_styling_enabled(log_item):
+        substring.color(_resolve_schema(msg_type, log_item))
+        if not _end_execution_schema(log_item):
+            substring.highlight(mark_pattern, _get_marker_schema())
+
     stylized_str.replace(matched_str, substring)
 
 
 def _get_traceback(traceback, log_item, mark_pattern):
-    schema = Color.Schema(**_styles(TRACEBACK).get(log_item.level.lower(), {}))
-    stylized_string = Color.stylize(traceback, schema)
-    stylized_string.highlight(traceback, _get_marker_schema(), schema, 
mark_pattern)
+    stylized_string = Color.stylize(traceback)
+    if _is_styling_enabled(log_item):
+        schema = Color.Schema(**_styles(TRACEBACK).get(log_item.level.lower(), 
{}))
+        stylized_string.color(schema)
+        stylized_string.highlight(mark_pattern, _get_marker_schema())
     return stylized_string
 
 
@@ -228,8 +232,8 @@ def _resolve_schema(msg_type, log_item):
         typed_schema_config = _styles(msg_type).get(log_item.level.lower())
         user_default_schema_config = _styles(msg_type).get('default')
         aria_schema_config = 
_DEFAULT_STYLE[msg_type].get(log_item.level.lower())
-        schema = Color.Schema(**(typed_schema_config or
-                                 user_default_schema_config or
-                                 aria_schema_config))
+        schema = Color.Schema(
+            **(typed_schema_config or user_default_schema_config or 
aria_schema_config)
+        )
 
     return schema

Reply via email to