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/13 09:00:57 UTC

incubator-ariatosca git commit: added load to logs, enables to get the formatted string

Repository: incubator-ariatosca
Updated Branches:
  refs/heads/ARIA-138-Make-logging-more-informative 6142dc44f -> 0374df5ff


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/0374df5f
Tree: http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/tree/0374df5f
Diff: http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/diff/0374df5f

Branch: refs/heads/ARIA-138-Make-logging-more-informative
Commit: 0374df5ff01604bba6c5c6f73c951fa2ff5ab44b
Parents: 6142dc4
Author: max-orlov <ma...@gigaspaces.com>
Authored: Thu Apr 13 12:00:52 2017 +0300
Committer: max-orlov <ma...@gigaspaces.com>
Committed: Thu Apr 13 12:00:52 2017 +0300

----------------------------------------------------------------------
 aria/cli/commands/executions.py |  4 +-
 aria/cli/commands/logs.py       |  2 +-
 aria/cli/execution_logging.py   | 82 +++++++++++++++++++++---------------
 3 files changed, 50 insertions(+), 38 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/0374df5f/aria/cli/commands/executions.py
----------------------------------------------------------------------
diff --git a/aria/cli/commands/executions.py b/aria/cli/commands/executions.py
index 4bdc481..a7579a5 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).log()
 
     except KeyboardInterrupt:
         _cancel_execution(workflow_runner, execution_thread, logger)
 
     for log in log_consumer:
-        execution_logging.log(log)
+        execution_logging.load_log(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/0374df5f/aria/cli/commands/logs.py
----------------------------------------------------------------------
diff --git a/aria/cli/commands/logs.py b/aria/cli/commands/logs.py
index 4d5d4e2..c665671 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).log()
         any_logs = True
 
     if not any_logs:

http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/0374df5f/aria/cli/execution_logging.py
----------------------------------------------------------------------
diff --git a/aria/cli/execution_logging.py b/aria/cli/execution_logging.py
index 9f83310..3532e60 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_log = _ExecutionLogging