You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@ariatosca.apache.org by mxmrlv <gi...@git.apache.org> on 2017/04/24 11:40:06 UTC

[GitHub] incubator-ariatosca pull request #109: ARIA-146-Support-colorful-execution-l...

GitHub user mxmrlv opened a pull request:

    https://github.com/apache/incubator-ariatosca/pull/109

    ARIA-146-Support-colorful-execution-logging

    

You can merge this pull request into a Git repository by running:

    $ git pull https://github.com/apache/incubator-ariatosca ARIA-146-Support-colorful-execution-logging

Alternatively you can review and apply these changes as the patch at:

    https://github.com/apache/incubator-ariatosca/pull/109.patch

To close this pull request, make a commit to your master/trunk branch
with (at least) the following in the commit message:

    This closes #109
    
----
commit 3a765743100d4390b77e813f2873482ac1770751
Author: max-orlov <ma...@gigaspaces.com>
Date:   2017-04-20T15:51:46Z

    wip

commit ca1baab678aa40057eacf5d08a5a83c89074b830
Author: max-orlov <ma...@gigaspaces.com>
Date:   2017-04-20T17:18:11Z

    wip2

commit 909ccaacedcd8366573470e0f60c39a91b69b730
Author: max-orlov <ma...@gigaspaces.com>
Date:   2017-04-21T10:53:34Z

    stylized the logs

commit dbcef5fdd2eca1c8dd4c7473846b401fa677d8fa
Author: max-orlov <ma...@gigaspaces.com>
Date:   2017-04-21T16:04:09Z

    added markingup

commit 1fc9ac756b39db9d14acc3cd47efcc8549a16039
Author: max-orlov <ma...@gigaspaces.com>
Date:   2017-04-21T16:48:07Z

    added markingup

commit ed350ca4220f3211ec1abf9ad946d0da19370893
Author: max-orlov <ma...@gigaspaces.com>
Date:   2017-04-21T23:42:48Z

    added easy pattern configurability

commit fea7a0c34f496f1b7d63a2684086753c71a35ea3
Author: max-orlov <ma...@gigaspaces.com>
Date:   2017-04-22T08:09:15Z

    modified executions logging

----


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] incubator-ariatosca pull request #109: ARIA-146-Support-colorful-execution-l...

Posted by mxmrlv <gi...@git.apache.org>.
Github user mxmrlv commented on a diff in the pull request:

    https://github.com/apache/incubator-ariatosca/pull/109#discussion_r113656162
  
    --- Diff: aria/cli/execution_logging.py ---
    @@ -12,67 +12,228 @@
     # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     # See the License for the specific language governing permissions and
     # limitations under the License.
    -
    +import os
    +import re
     from StringIO import StringIO
     
     from . import logger
    +from .color import Color
     from .env import env
     
    -DEFAULT_FORMATTING = {
    -    logger.NO_VERBOSE: {'message': '{item.msg}'},
    -    logger.LOW_VERBOSE: {
    -        'message': '{timestamp} | {item.level[0]} | {item.msg}',
    -        'timestamp': '%H:%M:%S'
    +
    +FIELD_TYPE = 'field_type'
    +LEVEL = 'level'
    +TIMESTAMP = 'timestamp'
    +MESSAGE = 'message'
    +IMPLEMENTATION = 'implementation'
    +INPUTS = 'inputs'
    +TRACEBACK = 'traceback'
    +MARKER = 'marker'
    +
    +FINAL_STATES = 'final_states'
    +SUCCESS_STATE = 'success'
    +CANCEL_STATE = 'cancel'
    +FAIL_STATE = 'fail'
    +
    +_EXECUTION_BASE_PATTERN = "\'.*\' workflow execution "
    +_SUCCESSFUL_EXECUTION_PATTERN = _EXECUTION_BASE_PATTERN + "succeeded"
    +_FAILED_EXECUTION_PATTERN = _EXECUTION_BASE_PATTERN + "failed"
    +_CANCELED_EXECUTION_PATTERN = _EXECUTION_BASE_PATTERN + "canceled"
    +
    +_TIMESTAMP_PATTERN = '.*({timestamp.*?}).*'
    --- End diff --
    
    maybe single Pattern for field type (with format)


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] incubator-ariatosca pull request #109: ARIA-146-Support-colorful-execution-l...

Posted by mxmrlv <gi...@git.apache.org>.
Github user mxmrlv commented on a diff in the pull request:

    https://github.com/apache/incubator-ariatosca/pull/109#discussion_r113237634
  
    --- Diff: aria/cli/color.py ---
    @@ -0,0 +1,73 @@
    +# Licensed to the Apache Software Foundation (ASF) under one or more
    +# contributor license agreements.  See the NOTICE file distributed with
    +# this work for additional information regarding copyright ownership.
    +# The ASF licenses this file to You under the Apache License, Version 2.0
    +# (the "License"); you may not use this file except in compliance with
    +# the License.  You may obtain a copy of the License at
    +#
    +#     http://www.apache.org/licenses/LICENSE-2.0
    +#
    +# Unless required by applicable law or agreed to in writing, software
    +# distributed under the License is distributed on an "AS IS" BASIS,
    +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    +# See the License for the specific language governing permissions and
    +# limitations under the License.
    +from StringIO import StringIO
    +
    +import colorama
    +
    +colorama.init()
    +
    +
    +def _get_colors(color_type):
    +    for name in dir(color_type):
    +        if not name.startswith('_'):
    +            yield (name.lower(), getattr(color_type, name))
    +
    +
    +class Color(object):
    +    Fore = colorama.Fore
    +    Back = colorama.Back
    +    Style = colorama.Style
    +
    +    _colors = {
    +        'fore': dict(_get_colors(Fore)),
    +        'back': dict(_get_colors(Back)),
    +        'style': dict(_get_colors(Style))
    +    }
    +
    +    class Schema(object):
    +        def __init__(self, **kwargs):
    +            """
    +            It is possible to provide fore, back and style arguments. each could be either
    +            the color is lower case letter, or the actual color from colorama.
    +
    +            """
    +            assert all(arg in Color._colors for arg in kwargs)
    +            self._kwargs = kwargs
    +            self._str = StringIO()
    +            for type_, colors in Color._colors.items():
    +                value = kwargs.pop(type_, None)
    +                # the former case is if the value is a string, the latter is in case of an object.
    +                self._str.write(colors.get(value) or value)
    +
    +        def __str__(self):
    +            return self._str.getvalue()
    +
    +        def __add__(self, other):
    +            return str(self) + str(other)
    +
    +        def __radd__(self, other):
    +            return str(other) + str(self)
    +
    +    @classmethod
    +    def stylize(cls, str_to_stylize, schema):
    +        return schema + str(str_to_stylize) + cls.Style.RESET_ALL
    +
    +    @classmethod
    +    def markup(cls, str_to_stylize, matches, schema):
    +        modified_str = str_to_stylize
    +        for group_index in xrange(len(matches.regs)):
    +            match = matches.group(group_index)
    +            modified_str = modified_str.replace(match, schema + match + cls.Back.RESET)
    --- End diff --
    
    revert back not to reset but to last back color


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] incubator-ariatosca pull request #109: ARIA-146-Support-colorful-execution-l...

Posted by mxmrlv <gi...@git.apache.org>.
Github user mxmrlv commented on a diff in the pull request:

    https://github.com/apache/incubator-ariatosca/pull/109#discussion_r113223683
  
    --- Diff: aria/cli/core/aria.py ---
    @@ -425,5 +425,14 @@ def service_template_name(required=False):
                 required=required,
                 help=helptexts.SERVICE_ID)
     
    +    @staticmethod
    +    def mark_pattern(default=None):
    +        return click.option(
    +            '-m',
    +            '--mark-pattern',
    +            help='pattern this',
    --- End diff --
    
    update


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] incubator-ariatosca pull request #109: ARIA-146-Support-colorful-execution-l...

Posted by mxmrlv <gi...@git.apache.org>.
Github user mxmrlv commented on a diff in the pull request:

    https://github.com/apache/incubator-ariatosca/pull/109#discussion_r113657022
  
    --- Diff: aria/cli/execution_logging.py ---
    @@ -12,67 +12,228 @@
     # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     # See the License for the specific language governing permissions and
     # limitations under the License.
    -
    +import os
    +import re
     from StringIO import StringIO
     
     from . import logger
    +from .color import Color
     from .env import env
     
    -DEFAULT_FORMATTING = {
    -    logger.NO_VERBOSE: {'message': '{item.msg}'},
    -    logger.LOW_VERBOSE: {
    -        'message': '{timestamp} | {item.level[0]} | {item.msg}',
    -        'timestamp': '%H:%M:%S'
    +
    +FIELD_TYPE = 'field_type'
    +LEVEL = 'level'
    +TIMESTAMP = 'timestamp'
    +MESSAGE = 'message'
    +IMPLEMENTATION = 'implementation'
    +INPUTS = 'inputs'
    +TRACEBACK = 'traceback'
    +MARKER = 'marker'
    +
    +FINAL_STATES = 'final_states'
    +SUCCESS_STATE = 'success'
    +CANCEL_STATE = 'cancel'
    +FAIL_STATE = 'fail'
    +
    +_EXECUTION_BASE_PATTERN = "\'.*\' workflow execution "
    +_SUCCESSFUL_EXECUTION_PATTERN = _EXECUTION_BASE_PATTERN + "succeeded"
    +_FAILED_EXECUTION_PATTERN = _EXECUTION_BASE_PATTERN + "failed"
    +_CANCELED_EXECUTION_PATTERN = _EXECUTION_BASE_PATTERN + "canceled"
    +
    +_TIMESTAMP_PATTERN = '.*({timestamp.*?}).*'
    +_LEVEL_PATTERN = '.*({level.*?}).*'
    +_MESSAGE_PATTERN = '.*({message.*?}).*'
    +_IMPLEMENTATION_PATTERN = '.*({implementation.*?}).*'
    +_INPUTS_PATTERN = '.*({inputs.*?}).*'
    +
    +_PATTERNS = {
    +    FINAL_STATES: {
    +        SUCCESS_STATE: re.compile(_SUCCESSFUL_EXECUTION_PATTERN),
    +        CANCEL_STATE: re.compile(_CANCELED_EXECUTION_PATTERN),
    +        FAIL_STATE: re.compile(_FAILED_EXECUTION_PATTERN),
         },
    -    logger.MEDIUM_VERBOSE: {
    -        'message': '{timestamp} | {item.level[0]} | {implementation} | {item.msg} ',
    -        'timestamp': '%H:%M:%S'
    +    FIELD_TYPE: {
    +        IMPLEMENTATION: re.compile(_IMPLEMENTATION_PATTERN),
    +        LEVEL: re.compile(_LEVEL_PATTERN),
    +        MESSAGE: re.compile(_MESSAGE_PATTERN),
    +        INPUTS: re.compile(_INPUTS_PATTERN),
    +        TIMESTAMP: re.compile(_TIMESTAMP_PATTERN)
    +    }
    +}
    +
    +_FINAL_STATES = {
    +    SUCCESS_STATE: Color.Fore.GREEN,
    +    CANCEL_STATE: Color.Fore.YELLOW,
    +    FAIL_STATE: Color.Fore.RED
    +}
    +
    +_DEFAULT_STYLE = {
    +    LEVEL: {
    +        'info': {'fore': 'lightmagenta_ex'},
    +        'debug': {'fore': 'lightmagenta_ex', 'style': 'dim'},
    +        'error': {'fore': 'red', 'style': 'bright'},
         },
    -    logger.HIGH_VERBOSE: {
    -        'message': '{timestamp} | {item.level[0]} | {implementation}({inputs}) | {item.msg} ',
    -        'timestamp': '%H:%M:%S'
    +    TIMESTAMP: {
    +        'info': {'fore': 'lightmagenta_ex'},
    +        'debug': {'fore': 'lightmagenta_ex', 'style': 'dim'},
    +        'error': {'fore': 'red', 'style': 'bright'},
         },
    -}
    +    MESSAGE: {
    +        'info': {'fore': 'lightblue_ex'},
    +        'debug': {'fore': 'lightblue_ex', 'style': 'dim'},
    +        'error': {'fore': 'red', 'style': 'bright'},
    +    },
    +    IMPLEMENTATION:{
    +        'info': {'fore': 'lightblack_ex'},
    +        'debug': {'fore': 'lightblack_ex', 'style': 'dim'},
    +        'error': {'fore': 'red', 'style': 'bright'},
    +    },
    +    INPUTS: {
    +        'info': {'fore': 'blue'},
    +        'debug': {'fore': 'blue', 'style': 'dim'},
    +        'error': {'fore': 'red', 'style': 'bright'},
    +    },
    +    TRACEBACK: {'error': {'fore': 'red'}},
     
    +    MARKER: 'lightyellow_ex'
    +}
     
    -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)
    +def stylize_log(item, mark_pattern):
     
    +    # implementation
         if item.task:
    -        formatting_kwargs['implementation'] = item.task.implementation
    -        formatting_kwargs['inputs'] = dict(i.unwrap() for i in item.task.inputs.values())
    +        # operation task
    +        implementation = item.task.implementation
    +        inputs = dict(i.unwrap() for i in item.task.inputs.values())
         else:
    -        formatting_kwargs['implementation'] = item.execution.workflow_name
    -        formatting_kwargs['inputs'] = dict(i.unwrap() for i in item.execution.inputs.values())
    +        # execution task
    +        implementation = item.execution.workflow_name
    +        inputs = dict(i.unwrap() for i in item.execution.inputs.values())
     
    -    if 'timestamp' in formatting:
    -        formatting_kwargs['timestamp'] = item.created_at.strftime(formatting['timestamp'])
    -    else:
    -        formatting_kwargs['timestamp'] = item.created_at
    -
    -    msg.write(formatting['message'].format(**formatting_kwargs))
    +    # TODO: use the is_workflow_log
    +    stylized_str = Color.stylize(_get_format())
    +    _update_level(stylized_str, item)
    +    _update_timestamp(stylized_str, item.created_at, item)
    +    _update_message(stylized_str, item.msg, item, mark_pattern)
    +    _update_inputs(stylized_str, inputs, item, mark_pattern)
    +    _update_implementation(stylized_str, implementation, item, mark_pattern)
     
    +    msg = StringIO()
    +    msg.write(str(stylized_str))
         # Add the exception and the error msg.
         if item.traceback and env.logging.verbosity_level >= logger.MEDIUM_VERBOSE:
    -        for line in item.traceback.splitlines(True):
    -            msg.write('\t' + '|' + line)
    +        msg.write(os.linesep)
    +        msg.writelines(_get_traceback('\t' + '|' + line, item, mark_pattern)
    +                       for line in item.traceback.splitlines(True))
     
         return msg.getvalue()
     
     
    -def log(item, *args, **kwargs):
    -    return getattr(env.logging.logger, item.level.lower())(_str(item), *args, **kwargs)
    +def log(item, mark_pattern=None, *args, **kwargs):
    +    leveled_log = getattr(env.logging.logger, item.level.lower())
    +    return leveled_log(stylize_log(item, mark_pattern), *args, **kwargs)
     
     
    -def log_list(iterator):
    +def log_list(iterator, mark_pattern=None):
         any_logs = False
         for item in iterator:
    -        log(item)
    +        log(item, mark_pattern)
             any_logs = True
         return any_logs
    +
    +
    +def _find_pattern(pattern, field_value):
    +    # TODO: this finds the matching field type according to a pattern
    +    match = re.match(pattern, field_value)
    +    if match:
    +        return match.group(1)
    +
    +
    +def _get_format():
    +    return env.config.logging.formats[env.logging.verbosity_level]
    +
    +
    +def _styles(field_type):
    --- End diff --
    
    get


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] incubator-ariatosca pull request #109: ARIA-146-Support-colorful-execution-l...

Posted by mxmrlv <gi...@git.apache.org>.
Github user mxmrlv commented on a diff in the pull request:

    https://github.com/apache/incubator-ariatosca/pull/109#discussion_r113233667
  
    --- Diff: aria/cli/execution_logging.py ---
    @@ -12,62 +12,208 @@
     # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     # See the License for the specific language governing permissions and
     # limitations under the License.
    -
    +import os
    +import re
     from StringIO import StringIO
    +from contextlib import contextmanager
     
     from . import logger
    +from .color import Color
     from .env import env
     
    +
    +LEVEL = 'level'
    +TIMESTAMP = 'timestamp'
    +MESSAGE = 'message'
    +IMPLEMENTATION = 'implementation'
    +INPUTS = 'inputs'
    +TRACEBACK = 'traceback'
    +MARKER = 'marker'
    +
    +FINAL_STATES = 'final_states'
    +SUCCESS_STATE = 'success'
    +CANCEL_STATE = 'cancel'
    +FAIL_STATE = 'fail'
    +
    +
    +_EXECUTION_BASE_PATTERN = "\'.*\' workflow execution "
    +_SUCCESSFUL_EXECUTION_PATTERN = _EXECUTION_BASE_PATTERN + "succeeded"
    +_FAILED_EXECUTION_PATTERN = _EXECUTION_BASE_PATTERN + "failed"
    +_CANCELED_EXECUTION_PATTERN = _EXECUTION_BASE_PATTERN + "canceled"
    +
     DEFAULT_FORMATTING = {
    -    logger.NO_VERBOSE: {'message': '{item.msg}'},
    +    logger.NO_VERBOSE: {'message': '{message}'},
         logger.LOW_VERBOSE: {
    -        'message': '{timestamp} | {item.level[0]} | {item.msg}',
    -        'timestamp': '%H:%M:%S'
    +        MESSAGE: '{timestamp} | {level} | {message}',
    +        LEVEL: '{level[0]}',
    +        TIMESTAMP: '%H:%M:%S',
         },
         logger.MEDIUM_VERBOSE: {
    -        'message': '{timestamp} | {item.level[0]} | {implementation} | {item.msg} ',
    -        'timestamp': '%H:%M:%S'
    +        MESSAGE: '{timestamp} | {level} | {implementation} | {message} ',
    +        LEVEL: '{level[0]}',
    +        TIMESTAMP: '%H:%M:%S'
         },
         logger.HIGH_VERBOSE: {
    -        'message': '{timestamp} | {item.level[0]} | {implementation}({inputs}) | {item.msg} ',
    -        'timestamp': '%H:%M:%S'
    +        MESSAGE: '{timestamp} | {level} | {implementation} | {inputs} | {message} ',
    +        LEVEL: '{level[0]}',
    +        TIMESTAMP: '%H:%M:%S'
    +    },
    +}
    +
    +DEFAULT_STYLING = {
    +    LEVEL: {
    +        'info': Color.Fore.LIGHTMAGENTA_EX,
    +        'debug': Color.Schema(fore=Color.Fore.LIGHTMAGENTA_EX, style=Color.Style.DIM),
    +        'error': Color.Schema(fore=Color.Fore.RED, style=Color.Style.BRIGHT),
         },
    +    TIMESTAMP: {
    +        'info': Color.Fore.LIGHTMAGENTA_EX,
    +        'debug': Color.Schema(fore=Color.Fore.LIGHTMAGENTA_EX, style=Color.Style.DIM),
    +        'error': Color.Schema(fore=Color.Fore.RED, style=Color.Style.BRIGHT),
    +    },
    +    MESSAGE: {
    +        'info': Color.Fore.LIGHTBLUE_EX,
    +        'debug': Color.Schema(fore=Color.Fore.LIGHTBLUE_EX, style=Color.Style.DIM),
    +        'error': Color.Schema(fore=Color.Fore.RED, style=Color.Style.BRIGHT),
    +    },
    +    IMPLEMENTATION: {
    +        'info': Color.Fore.LIGHTBLACK_EX,
    +        'debug': Color.Schema(fore=Color.Fore.LIGHTBLACK_EX, style=Color.Style.DIM),
    +        'error': Color.Schema(fore=Color.Fore.RED, style=Color.Style.BRIGHT),
    +    },
    +    INPUTS: {
    +        'info': Color.Fore.BLUE,
    +        'debug': Color.Schema(fore=Color.Fore.BLUE, style=Color.Style.DIM),
    +        'error': Color.Schema(fore=Color.Fore.RED, style=Color.Style.BRIGHT),
    +    },
    +    TRACEBACK: {'error': Color.Fore.RED},
    +
    +    MARKER: Color.Back.LIGHTYELLOW_EX,
    +    FINAL_STATES: {
    +        SUCCESS_STATE: Color.Fore.GREEN,
    +        CANCEL_STATE: Color.Fore.YELLOW,
    +        FAIL_STATE: Color.Fore.RED,
    +    }
     }
     
    +_PATTERNS = {
    +    SUCCESS_STATE: re.compile(_SUCCESSFUL_EXECUTION_PATTERN),
    +    CANCEL_STATE: re.compile(_CANCELED_EXECUTION_PATTERN),
    +    FAIL_STATE: re.compile(_FAILED_EXECUTION_PATTERN)
    +
    +}
    +
    +
    +class _StylizedLogs(object):
    +
    +    def __init__(self):
    +        self._formats = DEFAULT_FORMATTING
    +        self._styles = DEFAULT_STYLING
    +        self._mark_pattern = None
    +
    +    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 _implementation(self, implementation, log_item):
    +        return self._stylize(implementation, log_item, IMPLEMENTATION)
    +
    +    def _inputs(self, inputs, log_item):
    +        return self._stylize(inputs, log_item, INPUTS)
    +
    +    def _timestamp(self, timestamp, log_item):
    +        return self._stylize(timestamp, log_item, TIMESTAMP)
    +
    +    def _message(self, message, log_item):
    +        return self._stylize(message, log_item, MESSAGE)
    +
    +    def _traceback(self, traceback, log_item):
    +        return self._stylize(traceback, log_item, TRACEBACK)
    +
    +    def _level(self, log_item):
    +        return self._stylize(log_item.level[0], log_item, LEVEL)
    +
    +    def _stylize(self, msg, log_item, msg_type):
    +        schema = (self._final_string_schema(log_item.msg) or
    +                  self._styles[msg_type].get(log_item.level.lower(), ''))
    +        return Color.stylize(msg, schema)
    +
    +    def _markup(self, str_, original_message):
    +        if self._mark_pattern is None:
    +            return str_
    +        else:
    +            regex_pattern = re.compile(self._mark_pattern)
    +            matches = re.search(regex_pattern, original_message)
    +            if not matches:
    +                return str_
    +            return Color.markup(str_, matches, self._styles[MARKER])
    +
    +    def _final_string_schema(self, original_message):
    +        for state, pattern in _PATTERNS.items():
    +            if re.match(pattern, original_message):
    +                return self._styles[FINAL_STATES][state]
    +
    +    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)
    +
    +        # 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())
    +
    +        formatting_kwargs['implementation'] = self._markup(
    +            self._implementation(implementation, item), implementation)
    +        formatting_kwargs['inputs'] = self._markup(self._inputs(inputs, item), str(inputs))
    +
    +        # timestamp
    +        if 'timestamp' in formatting:
    +            timestamp = item.created_at.strftime(formatting['timestamp'])
    +        else:
    +            timestamp = item.created_at
    +        formatting_kwargs['timestamp'] = self._timestamp(timestamp, item)
    +
    +        # message
    +        formatting_kwargs['message'] = self._message(item.msg, item)
     
    -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()
    +        # The message would be marked out if containing the provided pattern
    +        msg.write(self._markup(formatting['message'].format(**formatting_kwargs), item.msg))
     
    -    formatting_kwargs = dict(item=item)
    +        # 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))
     
    -    if item.task:
    -        formatting_kwargs['implementation'] = item.task.implementation
    -        formatting_kwargs['inputs'] = dict(i.unwrap() for i in item.task.inputs.values())
    -    else:
    -        formatting_kwargs['implementation'] = item.execution.workflow_name
    -        formatting_kwargs['inputs'] = dict(i.unwrap() for i in item.execution.inputs.values())
    +        return msg.getvalue()
     
    -    if 'timestamp' in formatting:
    -        formatting_kwargs['timestamp'] = item.created_at.strftime(formatting['timestamp'])
    -    else:
    -        formatting_kwargs['timestamp'] = item.created_at
     
    -    msg.write(formatting['message'].format(**formatting_kwargs))
    +_stylize_log = _StylizedLogs()
     
    -    # Add the exception and the error msg.
    -    if item.traceback and env.logging.verbosity_level >= logger.MEDIUM_VERBOSE:
    -        for line in item.traceback.splitlines(True):
    -            msg.write('\t' + '|' + line)
     
    -    return msg.getvalue()
    +@contextmanager
    +def format(styles=None, formats=None, mark_pattern=None):
    --- End diff --
    
    read styles and formats from config (if defined); mark pattern can be passed directly via `log` and `log_list`


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] incubator-ariatosca pull request #109: ARIA-146-Support-colorful-execution-l...

Posted by asfgit <gi...@git.apache.org>.
Github user asfgit closed the pull request at:

    https://github.com/apache/incubator-ariatosca/pull/109


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] incubator-ariatosca pull request #109: ARIA-146-Support-colorful-execution-l...

Posted by mxmrlv <gi...@git.apache.org>.
Github user mxmrlv commented on a diff in the pull request:

    https://github.com/apache/incubator-ariatosca/pull/109#discussion_r113227289
  
    --- Diff: aria/cli/execution_logging.py ---
    @@ -12,62 +12,208 @@
     # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     # See the License for the specific language governing permissions and
     # limitations under the License.
    -
    +import os
    +import re
     from StringIO import StringIO
    +from contextlib import contextmanager
     
     from . import logger
    +from .color import Color
     from .env import env
     
    +
    +LEVEL = 'level'
    +TIMESTAMP = 'timestamp'
    +MESSAGE = 'message'
    +IMPLEMENTATION = 'implementation'
    +INPUTS = 'inputs'
    +TRACEBACK = 'traceback'
    +MARKER = 'marker'
    +
    +FINAL_STATES = 'final_states'
    +SUCCESS_STATE = 'success'
    +CANCEL_STATE = 'cancel'
    +FAIL_STATE = 'fail'
    +
    +
    +_EXECUTION_BASE_PATTERN = "\'.*\' workflow execution "
    +_SUCCESSFUL_EXECUTION_PATTERN = _EXECUTION_BASE_PATTERN + "succeeded"
    +_FAILED_EXECUTION_PATTERN = _EXECUTION_BASE_PATTERN + "failed"
    +_CANCELED_EXECUTION_PATTERN = _EXECUTION_BASE_PATTERN + "canceled"
    +
     DEFAULT_FORMATTING = {
    -    logger.NO_VERBOSE: {'message': '{item.msg}'},
    +    logger.NO_VERBOSE: {'message': '{message}'},
         logger.LOW_VERBOSE: {
    -        'message': '{timestamp} | {item.level[0]} | {item.msg}',
    -        'timestamp': '%H:%M:%S'
    +        MESSAGE: '{timestamp} | {level} | {message}',
    +        LEVEL: '{level[0]}',
    +        TIMESTAMP: '%H:%M:%S',
         },
         logger.MEDIUM_VERBOSE: {
    -        'message': '{timestamp} | {item.level[0]} | {implementation} | {item.msg} ',
    -        'timestamp': '%H:%M:%S'
    +        MESSAGE: '{timestamp} | {level} | {implementation} | {message} ',
    +        LEVEL: '{level[0]}',
    +        TIMESTAMP: '%H:%M:%S'
         },
         logger.HIGH_VERBOSE: {
    -        'message': '{timestamp} | {item.level[0]} | {implementation}({inputs}) | {item.msg} ',
    -        'timestamp': '%H:%M:%S'
    +        MESSAGE: '{timestamp} | {level} | {implementation} | {inputs} | {message} ',
    +        LEVEL: '{level[0]}',
    +        TIMESTAMP: '%H:%M:%S'
    +    },
    +}
    +
    +DEFAULT_STYLING = {
    +    LEVEL: {
    +        'info': Color.Fore.LIGHTMAGENTA_EX,
    +        'debug': Color.Schema(fore=Color.Fore.LIGHTMAGENTA_EX, style=Color.Style.DIM),
    +        'error': Color.Schema(fore=Color.Fore.RED, style=Color.Style.BRIGHT),
         },
    +    TIMESTAMP: {
    +        'info': Color.Fore.LIGHTMAGENTA_EX,
    +        'debug': Color.Schema(fore=Color.Fore.LIGHTMAGENTA_EX, style=Color.Style.DIM),
    +        'error': Color.Schema(fore=Color.Fore.RED, style=Color.Style.BRIGHT),
    +    },
    +    MESSAGE: {
    +        'info': Color.Fore.LIGHTBLUE_EX,
    +        'debug': Color.Schema(fore=Color.Fore.LIGHTBLUE_EX, style=Color.Style.DIM),
    +        'error': Color.Schema(fore=Color.Fore.RED, style=Color.Style.BRIGHT),
    +    },
    +    IMPLEMENTATION: {
    +        'info': Color.Fore.LIGHTBLACK_EX,
    +        'debug': Color.Schema(fore=Color.Fore.LIGHTBLACK_EX, style=Color.Style.DIM),
    +        'error': Color.Schema(fore=Color.Fore.RED, style=Color.Style.BRIGHT),
    +    },
    +    INPUTS: {
    +        'info': Color.Fore.BLUE,
    +        'debug': Color.Schema(fore=Color.Fore.BLUE, style=Color.Style.DIM),
    +        'error': Color.Schema(fore=Color.Fore.RED, style=Color.Style.BRIGHT),
    +    },
    +    TRACEBACK: {'error': Color.Fore.RED},
    --- End diff --
    
    default


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] incubator-ariatosca pull request #109: ARIA-146-Support-colorful-execution-l...

Posted by mxmrlv <gi...@git.apache.org>.
Github user mxmrlv commented on a diff in the pull request:

    https://github.com/apache/incubator-ariatosca/pull/109#discussion_r113655205
  
    --- Diff: aria/cli/config/config_template.yaml ---
    @@ -10,3 +9,39 @@ logging:
     
         # main logger of the cli. provides basic descriptions for executed operations.
         aria.cli.main: info
    +
    +  execution:
    +    formats:
    +      # According to verbosity level 0 - no verbose. 3 - high verbose
    +      0: '{message}'
    --- End diff --
    
    hard code as well


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] incubator-ariatosca pull request #109: ARIA-146-Support-colorful-execution-l...

Posted by mxmrlv <gi...@git.apache.org>.
Github user mxmrlv commented on a diff in the pull request:

    https://github.com/apache/incubator-ariatosca/pull/109#discussion_r113225121
  
    --- Diff: aria/cli/execution_logging.py ---
    @@ -12,62 +12,208 @@
     # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     # See the License for the specific language governing permissions and
     # limitations under the License.
    -
    +import os
    +import re
     from StringIO import StringIO
    +from contextlib import contextmanager
     
     from . import logger
    +from .color import Color
     from .env import env
     
    +
    +LEVEL = 'level'
    +TIMESTAMP = 'timestamp'
    +MESSAGE = 'message'
    +IMPLEMENTATION = 'implementation'
    +INPUTS = 'inputs'
    +TRACEBACK = 'traceback'
    +MARKER = 'marker'
    +
    +FINAL_STATES = 'final_states'
    +SUCCESS_STATE = 'success'
    +CANCEL_STATE = 'cancel'
    +FAIL_STATE = 'fail'
    +
    +
    +_EXECUTION_BASE_PATTERN = "\'.*\' workflow execution "
    +_SUCCESSFUL_EXECUTION_PATTERN = _EXECUTION_BASE_PATTERN + "succeeded"
    +_FAILED_EXECUTION_PATTERN = _EXECUTION_BASE_PATTERN + "failed"
    +_CANCELED_EXECUTION_PATTERN = _EXECUTION_BASE_PATTERN + "canceled"
    +
     DEFAULT_FORMATTING = {
    -    logger.NO_VERBOSE: {'message': '{item.msg}'},
    +    logger.NO_VERBOSE: {'message': '{message}'},
         logger.LOW_VERBOSE: {
    -        'message': '{timestamp} | {item.level[0]} | {item.msg}',
    -        'timestamp': '%H:%M:%S'
    +        MESSAGE: '{timestamp} | {level} | {message}',
    +        LEVEL: '{level[0]}',
    +        TIMESTAMP: '%H:%M:%S',
         },
         logger.MEDIUM_VERBOSE: {
    -        'message': '{timestamp} | {item.level[0]} | {implementation} | {item.msg} ',
    -        'timestamp': '%H:%M:%S'
    +        MESSAGE: '{timestamp} | {level} | {implementation} | {message} ',
    --- End diff --
    
    space


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] incubator-ariatosca pull request #109: ARIA-146-Support-colorful-execution-l...

Posted by mxmrlv <gi...@git.apache.org>.
Github user mxmrlv commented on a diff in the pull request:

    https://github.com/apache/incubator-ariatosca/pull/109#discussion_r113656446
  
    --- Diff: aria/cli/execution_logging.py ---
    @@ -12,67 +12,228 @@
     # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     # See the License for the specific language governing permissions and
     # limitations under the License.
    -
    +import os
    +import re
     from StringIO import StringIO
     
     from . import logger
    +from .color import Color
     from .env import env
     
    -DEFAULT_FORMATTING = {
    -    logger.NO_VERBOSE: {'message': '{item.msg}'},
    -    logger.LOW_VERBOSE: {
    -        'message': '{timestamp} | {item.level[0]} | {item.msg}',
    -        'timestamp': '%H:%M:%S'
    +
    +FIELD_TYPE = 'field_type'
    +LEVEL = 'level'
    +TIMESTAMP = 'timestamp'
    +MESSAGE = 'message'
    +IMPLEMENTATION = 'implementation'
    +INPUTS = 'inputs'
    +TRACEBACK = 'traceback'
    +MARKER = 'marker'
    +
    +FINAL_STATES = 'final_states'
    +SUCCESS_STATE = 'success'
    +CANCEL_STATE = 'cancel'
    +FAIL_STATE = 'fail'
    +
    +_EXECUTION_BASE_PATTERN = "\'.*\' workflow execution "
    +_SUCCESSFUL_EXECUTION_PATTERN = _EXECUTION_BASE_PATTERN + "succeeded"
    +_FAILED_EXECUTION_PATTERN = _EXECUTION_BASE_PATTERN + "failed"
    +_CANCELED_EXECUTION_PATTERN = _EXECUTION_BASE_PATTERN + "canceled"
    +
    +_TIMESTAMP_PATTERN = '.*({timestamp.*?}).*'
    +_LEVEL_PATTERN = '.*({level.*?}).*'
    +_MESSAGE_PATTERN = '.*({message.*?}).*'
    +_IMPLEMENTATION_PATTERN = '.*({implementation.*?}).*'
    +_INPUTS_PATTERN = '.*({inputs.*?}).*'
    +
    +_PATTERNS = {
    +    FINAL_STATES: {
    +        SUCCESS_STATE: re.compile(_SUCCESSFUL_EXECUTION_PATTERN),
    +        CANCEL_STATE: re.compile(_CANCELED_EXECUTION_PATTERN),
    +        FAIL_STATE: re.compile(_FAILED_EXECUTION_PATTERN),
         },
    -    logger.MEDIUM_VERBOSE: {
    -        'message': '{timestamp} | {item.level[0]} | {implementation} | {item.msg} ',
    -        'timestamp': '%H:%M:%S'
    +    FIELD_TYPE: {
    +        IMPLEMENTATION: re.compile(_IMPLEMENTATION_PATTERN),
    +        LEVEL: re.compile(_LEVEL_PATTERN),
    +        MESSAGE: re.compile(_MESSAGE_PATTERN),
    +        INPUTS: re.compile(_INPUTS_PATTERN),
    +        TIMESTAMP: re.compile(_TIMESTAMP_PATTERN)
    +    }
    +}
    +
    +_FINAL_STATES = {
    +    SUCCESS_STATE: Color.Fore.GREEN,
    +    CANCEL_STATE: Color.Fore.YELLOW,
    +    FAIL_STATE: Color.Fore.RED
    +}
    +
    +_DEFAULT_STYLE = {
    +    LEVEL: {
    +        'info': {'fore': 'lightmagenta_ex'},
    +        'debug': {'fore': 'lightmagenta_ex', 'style': 'dim'},
    +        'error': {'fore': 'red', 'style': 'bright'},
         },
    -    logger.HIGH_VERBOSE: {
    -        'message': '{timestamp} | {item.level[0]} | {implementation}({inputs}) | {item.msg} ',
    -        'timestamp': '%H:%M:%S'
    +    TIMESTAMP: {
    +        'info': {'fore': 'lightmagenta_ex'},
    +        'debug': {'fore': 'lightmagenta_ex', 'style': 'dim'},
    +        'error': {'fore': 'red', 'style': 'bright'},
         },
    -}
    +    MESSAGE: {
    +        'info': {'fore': 'lightblue_ex'},
    +        'debug': {'fore': 'lightblue_ex', 'style': 'dim'},
    +        'error': {'fore': 'red', 'style': 'bright'},
    +    },
    +    IMPLEMENTATION:{
    +        'info': {'fore': 'lightblack_ex'},
    +        'debug': {'fore': 'lightblack_ex', 'style': 'dim'},
    +        'error': {'fore': 'red', 'style': 'bright'},
    +    },
    +    INPUTS: {
    +        'info': {'fore': 'blue'},
    +        'debug': {'fore': 'blue', 'style': 'dim'},
    +        'error': {'fore': 'red', 'style': 'bright'},
    +    },
    +    TRACEBACK: {'error': {'fore': 'red'}},
     
    +    MARKER: 'lightyellow_ex'
    +}
     
    -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)
    +def stylize_log(item, mark_pattern):
     
    +    # implementation
         if item.task:
    -        formatting_kwargs['implementation'] = item.task.implementation
    -        formatting_kwargs['inputs'] = dict(i.unwrap() for i in item.task.inputs.values())
    +        # operation task
    +        implementation = item.task.implementation
    +        inputs = dict(i.unwrap() for i in item.task.inputs.values())
         else:
    -        formatting_kwargs['implementation'] = item.execution.workflow_name
    -        formatting_kwargs['inputs'] = dict(i.unwrap() for i in item.execution.inputs.values())
    +        # execution task
    +        implementation = item.execution.workflow_name
    +        inputs = dict(i.unwrap() for i in item.execution.inputs.values())
     
    -    if 'timestamp' in formatting:
    -        formatting_kwargs['timestamp'] = item.created_at.strftime(formatting['timestamp'])
    -    else:
    -        formatting_kwargs['timestamp'] = item.created_at
    -
    -    msg.write(formatting['message'].format(**formatting_kwargs))
    +    # TODO: use the is_workflow_log
    --- End diff --
    
    remove


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] incubator-ariatosca pull request #109: ARIA-146-Support-colorful-execution-l...

Posted by mxmrlv <gi...@git.apache.org>.
Github user mxmrlv commented on a diff in the pull request:

    https://github.com/apache/incubator-ariatosca/pull/109#discussion_r113657115
  
    --- Diff: aria/cli/execution_logging.py ---
    @@ -12,67 +12,228 @@
     # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     # See the License for the specific language governing permissions and
     # limitations under the License.
    -
    +import os
    +import re
     from StringIO import StringIO
     
     from . import logger
    +from .color import Color
     from .env import env
     
    -DEFAULT_FORMATTING = {
    -    logger.NO_VERBOSE: {'message': '{item.msg}'},
    -    logger.LOW_VERBOSE: {
    -        'message': '{timestamp} | {item.level[0]} | {item.msg}',
    -        'timestamp': '%H:%M:%S'
    +
    +FIELD_TYPE = 'field_type'
    +LEVEL = 'level'
    +TIMESTAMP = 'timestamp'
    +MESSAGE = 'message'
    +IMPLEMENTATION = 'implementation'
    +INPUTS = 'inputs'
    +TRACEBACK = 'traceback'
    +MARKER = 'marker'
    +
    +FINAL_STATES = 'final_states'
    +SUCCESS_STATE = 'success'
    +CANCEL_STATE = 'cancel'
    +FAIL_STATE = 'fail'
    +
    +_EXECUTION_BASE_PATTERN = "\'.*\' workflow execution "
    +_SUCCESSFUL_EXECUTION_PATTERN = _EXECUTION_BASE_PATTERN + "succeeded"
    +_FAILED_EXECUTION_PATTERN = _EXECUTION_BASE_PATTERN + "failed"
    +_CANCELED_EXECUTION_PATTERN = _EXECUTION_BASE_PATTERN + "canceled"
    +
    +_TIMESTAMP_PATTERN = '.*({timestamp.*?}).*'
    +_LEVEL_PATTERN = '.*({level.*?}).*'
    +_MESSAGE_PATTERN = '.*({message.*?}).*'
    +_IMPLEMENTATION_PATTERN = '.*({implementation.*?}).*'
    +_INPUTS_PATTERN = '.*({inputs.*?}).*'
    +
    +_PATTERNS = {
    +    FINAL_STATES: {
    +        SUCCESS_STATE: re.compile(_SUCCESSFUL_EXECUTION_PATTERN),
    +        CANCEL_STATE: re.compile(_CANCELED_EXECUTION_PATTERN),
    +        FAIL_STATE: re.compile(_FAILED_EXECUTION_PATTERN),
         },
    -    logger.MEDIUM_VERBOSE: {
    -        'message': '{timestamp} | {item.level[0]} | {implementation} | {item.msg} ',
    -        'timestamp': '%H:%M:%S'
    +    FIELD_TYPE: {
    +        IMPLEMENTATION: re.compile(_IMPLEMENTATION_PATTERN),
    +        LEVEL: re.compile(_LEVEL_PATTERN),
    +        MESSAGE: re.compile(_MESSAGE_PATTERN),
    +        INPUTS: re.compile(_INPUTS_PATTERN),
    +        TIMESTAMP: re.compile(_TIMESTAMP_PATTERN)
    +    }
    +}
    +
    +_FINAL_STATES = {
    +    SUCCESS_STATE: Color.Fore.GREEN,
    +    CANCEL_STATE: Color.Fore.YELLOW,
    +    FAIL_STATE: Color.Fore.RED
    +}
    +
    +_DEFAULT_STYLE = {
    +    LEVEL: {
    +        'info': {'fore': 'lightmagenta_ex'},
    +        'debug': {'fore': 'lightmagenta_ex', 'style': 'dim'},
    +        'error': {'fore': 'red', 'style': 'bright'},
         },
    -    logger.HIGH_VERBOSE: {
    -        'message': '{timestamp} | {item.level[0]} | {implementation}({inputs}) | {item.msg} ',
    -        'timestamp': '%H:%M:%S'
    +    TIMESTAMP: {
    +        'info': {'fore': 'lightmagenta_ex'},
    +        'debug': {'fore': 'lightmagenta_ex', 'style': 'dim'},
    +        'error': {'fore': 'red', 'style': 'bright'},
         },
    -}
    +    MESSAGE: {
    +        'info': {'fore': 'lightblue_ex'},
    +        'debug': {'fore': 'lightblue_ex', 'style': 'dim'},
    +        'error': {'fore': 'red', 'style': 'bright'},
    +    },
    +    IMPLEMENTATION:{
    +        'info': {'fore': 'lightblack_ex'},
    +        'debug': {'fore': 'lightblack_ex', 'style': 'dim'},
    +        'error': {'fore': 'red', 'style': 'bright'},
    +    },
    +    INPUTS: {
    +        'info': {'fore': 'blue'},
    +        'debug': {'fore': 'blue', 'style': 'dim'},
    +        'error': {'fore': 'red', 'style': 'bright'},
    +    },
    +    TRACEBACK: {'error': {'fore': 'red'}},
     
    +    MARKER: 'lightyellow_ex'
    +}
     
    -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)
    +def stylize_log(item, mark_pattern):
     
    +    # implementation
         if item.task:
    -        formatting_kwargs['implementation'] = item.task.implementation
    -        formatting_kwargs['inputs'] = dict(i.unwrap() for i in item.task.inputs.values())
    +        # operation task
    +        implementation = item.task.implementation
    +        inputs = dict(i.unwrap() for i in item.task.inputs.values())
         else:
    -        formatting_kwargs['implementation'] = item.execution.workflow_name
    -        formatting_kwargs['inputs'] = dict(i.unwrap() for i in item.execution.inputs.values())
    +        # execution task
    +        implementation = item.execution.workflow_name
    +        inputs = dict(i.unwrap() for i in item.execution.inputs.values())
     
    -    if 'timestamp' in formatting:
    -        formatting_kwargs['timestamp'] = item.created_at.strftime(formatting['timestamp'])
    -    else:
    -        formatting_kwargs['timestamp'] = item.created_at
    -
    -    msg.write(formatting['message'].format(**formatting_kwargs))
    +    # TODO: use the is_workflow_log
    +    stylized_str = Color.stylize(_get_format())
    +    _update_level(stylized_str, item)
    +    _update_timestamp(stylized_str, item.created_at, item)
    +    _update_message(stylized_str, item.msg, item, mark_pattern)
    +    _update_inputs(stylized_str, inputs, item, mark_pattern)
    +    _update_implementation(stylized_str, implementation, item, mark_pattern)
     
    +    msg = StringIO()
    +    msg.write(str(stylized_str))
         # Add the exception and the error msg.
         if item.traceback and env.logging.verbosity_level >= logger.MEDIUM_VERBOSE:
    -        for line in item.traceback.splitlines(True):
    -            msg.write('\t' + '|' + line)
    +        msg.write(os.linesep)
    +        msg.writelines(_get_traceback('\t' + '|' + line, item, mark_pattern)
    +                       for line in item.traceback.splitlines(True))
     
         return msg.getvalue()
     
     
    -def log(item, *args, **kwargs):
    -    return getattr(env.logging.logger, item.level.lower())(_str(item), *args, **kwargs)
    +def log(item, mark_pattern=None, *args, **kwargs):
    +    leveled_log = getattr(env.logging.logger, item.level.lower())
    +    return leveled_log(stylize_log(item, mark_pattern), *args, **kwargs)
     
     
    -def log_list(iterator):
    +def log_list(iterator, mark_pattern=None):
         any_logs = False
         for item in iterator:
    -        log(item)
    +        log(item, mark_pattern)
             any_logs = True
         return any_logs
    +
    +
    +def _find_pattern(pattern, field_value):
    +    # TODO: this finds the matching field type according to a pattern
    +    match = re.match(pattern, field_value)
    +    if match:
    +        return match.group(1)
    +
    +
    +def _get_format():
    +    return env.config.logging.formats[env.logging.verbosity_level]
    +
    +
    +def _styles(field_type):
    +    return env.config.logging.styles[field_type]
    +
    +
    +def _is_styling_enabled(log_item):
    +    return (
    --- End diff --
    
    one line


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] incubator-ariatosca pull request #109: ARIA-146-Support-colorful-execution-l...

Posted by mxmrlv <gi...@git.apache.org>.
Github user mxmrlv commented on a diff in the pull request:

    https://github.com/apache/incubator-ariatosca/pull/109#discussion_r113231457
  
    --- Diff: aria/cli/execution_logging.py ---
    @@ -12,62 +12,208 @@
     # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     # See the License for the specific language governing permissions and
     # limitations under the License.
    -
    +import os
    +import re
     from StringIO import StringIO
    +from contextlib import contextmanager
     
     from . import logger
    +from .color import Color
     from .env import env
     
    +
    +LEVEL = 'level'
    +TIMESTAMP = 'timestamp'
    +MESSAGE = 'message'
    +IMPLEMENTATION = 'implementation'
    +INPUTS = 'inputs'
    +TRACEBACK = 'traceback'
    +MARKER = 'marker'
    +
    +FINAL_STATES = 'final_states'
    +SUCCESS_STATE = 'success'
    +CANCEL_STATE = 'cancel'
    +FAIL_STATE = 'fail'
    +
    +
    +_EXECUTION_BASE_PATTERN = "\'.*\' workflow execution "
    +_SUCCESSFUL_EXECUTION_PATTERN = _EXECUTION_BASE_PATTERN + "succeeded"
    +_FAILED_EXECUTION_PATTERN = _EXECUTION_BASE_PATTERN + "failed"
    +_CANCELED_EXECUTION_PATTERN = _EXECUTION_BASE_PATTERN + "canceled"
    +
     DEFAULT_FORMATTING = {
    -    logger.NO_VERBOSE: {'message': '{item.msg}'},
    +    logger.NO_VERBOSE: {'message': '{message}'},
         logger.LOW_VERBOSE: {
    -        'message': '{timestamp} | {item.level[0]} | {item.msg}',
    -        'timestamp': '%H:%M:%S'
    +        MESSAGE: '{timestamp} | {level} | {message}',
    +        LEVEL: '{level[0]}',
    +        TIMESTAMP: '%H:%M:%S',
         },
         logger.MEDIUM_VERBOSE: {
    -        'message': '{timestamp} | {item.level[0]} | {implementation} | {item.msg} ',
    -        'timestamp': '%H:%M:%S'
    +        MESSAGE: '{timestamp} | {level} | {implementation} | {message} ',
    +        LEVEL: '{level[0]}',
    +        TIMESTAMP: '%H:%M:%S'
         },
         logger.HIGH_VERBOSE: {
    -        'message': '{timestamp} | {item.level[0]} | {implementation}({inputs}) | {item.msg} ',
    -        'timestamp': '%H:%M:%S'
    +        MESSAGE: '{timestamp} | {level} | {implementation} | {inputs} | {message} ',
    +        LEVEL: '{level[0]}',
    +        TIMESTAMP: '%H:%M:%S'
    +    },
    +}
    +
    +DEFAULT_STYLING = {
    +    LEVEL: {
    +        'info': Color.Fore.LIGHTMAGENTA_EX,
    +        'debug': Color.Schema(fore=Color.Fore.LIGHTMAGENTA_EX, style=Color.Style.DIM),
    +        'error': Color.Schema(fore=Color.Fore.RED, style=Color.Style.BRIGHT),
         },
    +    TIMESTAMP: {
    +        'info': Color.Fore.LIGHTMAGENTA_EX,
    +        'debug': Color.Schema(fore=Color.Fore.LIGHTMAGENTA_EX, style=Color.Style.DIM),
    +        'error': Color.Schema(fore=Color.Fore.RED, style=Color.Style.BRIGHT),
    +    },
    +    MESSAGE: {
    +        'info': Color.Fore.LIGHTBLUE_EX,
    +        'debug': Color.Schema(fore=Color.Fore.LIGHTBLUE_EX, style=Color.Style.DIM),
    +        'error': Color.Schema(fore=Color.Fore.RED, style=Color.Style.BRIGHT),
    +    },
    +    IMPLEMENTATION: {
    +        'info': Color.Fore.LIGHTBLACK_EX,
    +        'debug': Color.Schema(fore=Color.Fore.LIGHTBLACK_EX, style=Color.Style.DIM),
    +        'error': Color.Schema(fore=Color.Fore.RED, style=Color.Style.BRIGHT),
    +    },
    +    INPUTS: {
    +        'info': Color.Fore.BLUE,
    +        'debug': Color.Schema(fore=Color.Fore.BLUE, style=Color.Style.DIM),
    +        'error': Color.Schema(fore=Color.Fore.RED, style=Color.Style.BRIGHT),
    +    },
    +    TRACEBACK: {'error': Color.Fore.RED},
    +
    +    MARKER: Color.Back.LIGHTYELLOW_EX,
    +    FINAL_STATES: {
    +        SUCCESS_STATE: Color.Fore.GREEN,
    +        CANCEL_STATE: Color.Fore.YELLOW,
    +        FAIL_STATE: Color.Fore.RED,
    +    }
     }
     
    +_PATTERNS = {
    +    SUCCESS_STATE: re.compile(_SUCCESSFUL_EXECUTION_PATTERN),
    +    CANCEL_STATE: re.compile(_CANCELED_EXECUTION_PATTERN),
    +    FAIL_STATE: re.compile(_FAILED_EXECUTION_PATTERN)
    +
    +}
    +
    +
    +class _StylizedLogs(object):
    +
    +    def __init__(self):
    +        self._formats = DEFAULT_FORMATTING
    +        self._styles = DEFAULT_STYLING
    +        self._mark_pattern = None
    +
    +    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 _implementation(self, implementation, log_item):
    +        return self._stylize(implementation, log_item, IMPLEMENTATION)
    +
    +    def _inputs(self, inputs, log_item):
    +        return self._stylize(inputs, log_item, INPUTS)
    +
    +    def _timestamp(self, timestamp, log_item):
    +        return self._stylize(timestamp, log_item, TIMESTAMP)
    +
    +    def _message(self, message, log_item):
    +        return self._stylize(message, log_item, MESSAGE)
    +
    +    def _traceback(self, traceback, log_item):
    +        return self._stylize(traceback, log_item, TRACEBACK)
    +
    +    def _level(self, log_item):
    +        return self._stylize(log_item.level[0], log_item, LEVEL)
    +
    +    def _stylize(self, msg, log_item, msg_type):
    +        schema = (self._final_string_schema(log_item.msg) or
    +                  self._styles[msg_type].get(log_item.level.lower(), ''))
    +        return Color.stylize(msg, schema)
    +
    +    def _markup(self, str_, original_message):
    +        if self._mark_pattern is None:
    +            return str_
    +        else:
    +            regex_pattern = re.compile(self._mark_pattern)
    +            matches = re.search(regex_pattern, original_message)
    +            if not matches:
    +                return str_
    +            return Color.markup(str_, matches, self._styles[MARKER])
    +
    +    def _final_string_schema(self, original_message):
    --- End diff --
    
    sheesh


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] incubator-ariatosca pull request #109: ARIA-146-Support-colorful-execution-l...

Posted by mxmrlv <gi...@git.apache.org>.
Github user mxmrlv commented on a diff in the pull request:

    https://github.com/apache/incubator-ariatosca/pull/109#discussion_r113223779
  
    --- Diff: aria/cli/core/aria.py ---
    @@ -425,5 +425,14 @@ def service_template_name(required=False):
                 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
    --- End diff --
    
    required=false


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] incubator-ariatosca pull request #109: ARIA-146-Support-colorful-execution-l...

Posted by mxmrlv <gi...@git.apache.org>.
Github user mxmrlv commented on a diff in the pull request:

    https://github.com/apache/incubator-ariatosca/pull/109#discussion_r113659270
  
    --- Diff: aria/cli/execution_logging.py ---
    @@ -12,67 +12,228 @@
     # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     # See the License for the specific language governing permissions and
     # limitations under the License.
    -
    +import os
    +import re
     from StringIO import StringIO
     
     from . import logger
    +from .color import Color
     from .env import env
     
    -DEFAULT_FORMATTING = {
    -    logger.NO_VERBOSE: {'message': '{item.msg}'},
    -    logger.LOW_VERBOSE: {
    -        'message': '{timestamp} | {item.level[0]} | {item.msg}',
    -        'timestamp': '%H:%M:%S'
    +
    +FIELD_TYPE = 'field_type'
    +LEVEL = 'level'
    +TIMESTAMP = 'timestamp'
    +MESSAGE = 'message'
    +IMPLEMENTATION = 'implementation'
    +INPUTS = 'inputs'
    +TRACEBACK = 'traceback'
    +MARKER = 'marker'
    +
    +FINAL_STATES = 'final_states'
    +SUCCESS_STATE = 'success'
    +CANCEL_STATE = 'cancel'
    +FAIL_STATE = 'fail'
    +
    +_EXECUTION_BASE_PATTERN = "\'.*\' workflow execution "
    +_SUCCESSFUL_EXECUTION_PATTERN = _EXECUTION_BASE_PATTERN + "succeeded"
    +_FAILED_EXECUTION_PATTERN = _EXECUTION_BASE_PATTERN + "failed"
    +_CANCELED_EXECUTION_PATTERN = _EXECUTION_BASE_PATTERN + "canceled"
    +
    +_TIMESTAMP_PATTERN = '.*({timestamp.*?}).*'
    +_LEVEL_PATTERN = '.*({level.*?}).*'
    +_MESSAGE_PATTERN = '.*({message.*?}).*'
    +_IMPLEMENTATION_PATTERN = '.*({implementation.*?}).*'
    +_INPUTS_PATTERN = '.*({inputs.*?}).*'
    +
    +_PATTERNS = {
    +    FINAL_STATES: {
    +        SUCCESS_STATE: re.compile(_SUCCESSFUL_EXECUTION_PATTERN),
    +        CANCEL_STATE: re.compile(_CANCELED_EXECUTION_PATTERN),
    +        FAIL_STATE: re.compile(_FAILED_EXECUTION_PATTERN),
         },
    -    logger.MEDIUM_VERBOSE: {
    -        'message': '{timestamp} | {item.level[0]} | {implementation} | {item.msg} ',
    -        'timestamp': '%H:%M:%S'
    +    FIELD_TYPE: {
    +        IMPLEMENTATION: re.compile(_IMPLEMENTATION_PATTERN),
    +        LEVEL: re.compile(_LEVEL_PATTERN),
    +        MESSAGE: re.compile(_MESSAGE_PATTERN),
    +        INPUTS: re.compile(_INPUTS_PATTERN),
    +        TIMESTAMP: re.compile(_TIMESTAMP_PATTERN)
    +    }
    +}
    +
    +_FINAL_STATES = {
    +    SUCCESS_STATE: Color.Fore.GREEN,
    +    CANCEL_STATE: Color.Fore.YELLOW,
    +    FAIL_STATE: Color.Fore.RED
    +}
    +
    +_DEFAULT_STYLE = {
    +    LEVEL: {
    +        'info': {'fore': 'lightmagenta_ex'},
    +        'debug': {'fore': 'lightmagenta_ex', 'style': 'dim'},
    +        'error': {'fore': 'red', 'style': 'bright'},
         },
    -    logger.HIGH_VERBOSE: {
    -        'message': '{timestamp} | {item.level[0]} | {implementation}({inputs}) | {item.msg} ',
    -        'timestamp': '%H:%M:%S'
    +    TIMESTAMP: {
    +        'info': {'fore': 'lightmagenta_ex'},
    +        'debug': {'fore': 'lightmagenta_ex', 'style': 'dim'},
    +        'error': {'fore': 'red', 'style': 'bright'},
         },
    -}
    +    MESSAGE: {
    +        'info': {'fore': 'lightblue_ex'},
    +        'debug': {'fore': 'lightblue_ex', 'style': 'dim'},
    +        'error': {'fore': 'red', 'style': 'bright'},
    +    },
    +    IMPLEMENTATION:{
    +        'info': {'fore': 'lightblack_ex'},
    +        'debug': {'fore': 'lightblack_ex', 'style': 'dim'},
    +        'error': {'fore': 'red', 'style': 'bright'},
    +    },
    +    INPUTS: {
    +        'info': {'fore': 'blue'},
    +        'debug': {'fore': 'blue', 'style': 'dim'},
    +        'error': {'fore': 'red', 'style': 'bright'},
    +    },
    +    TRACEBACK: {'error': {'fore': 'red'}},
     
    +    MARKER: 'lightyellow_ex'
    +}
     
    -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)
    +def stylize_log(item, mark_pattern):
     
    +    # implementation
         if item.task:
    -        formatting_kwargs['implementation'] = item.task.implementation
    -        formatting_kwargs['inputs'] = dict(i.unwrap() for i in item.task.inputs.values())
    +        # operation task
    +        implementation = item.task.implementation
    +        inputs = dict(i.unwrap() for i in item.task.inputs.values())
         else:
    -        formatting_kwargs['implementation'] = item.execution.workflow_name
    -        formatting_kwargs['inputs'] = dict(i.unwrap() for i in item.execution.inputs.values())
    +        # execution task
    +        implementation = item.execution.workflow_name
    +        inputs = dict(i.unwrap() for i in item.execution.inputs.values())
     
    -    if 'timestamp' in formatting:
    -        formatting_kwargs['timestamp'] = item.created_at.strftime(formatting['timestamp'])
    -    else:
    -        formatting_kwargs['timestamp'] = item.created_at
    -
    -    msg.write(formatting['message'].format(**formatting_kwargs))
    +    # TODO: use the is_workflow_log
    +    stylized_str = Color.stylize(_get_format())
    +    _update_level(stylized_str, item)
    +    _update_timestamp(stylized_str, item.created_at, item)
    +    _update_message(stylized_str, item.msg, item, mark_pattern)
    +    _update_inputs(stylized_str, inputs, item, mark_pattern)
    +    _update_implementation(stylized_str, implementation, item, mark_pattern)
     
    +    msg = StringIO()
    +    msg.write(str(stylized_str))
         # Add the exception and the error msg.
         if item.traceback and env.logging.verbosity_level >= logger.MEDIUM_VERBOSE:
    -        for line in item.traceback.splitlines(True):
    -            msg.write('\t' + '|' + line)
    +        msg.write(os.linesep)
    +        msg.writelines(_get_traceback('\t' + '|' + line, item, mark_pattern)
    +                       for line in item.traceback.splitlines(True))
     
         return msg.getvalue()
     
     
    -def log(item, *args, **kwargs):
    -    return getattr(env.logging.logger, item.level.lower())(_str(item), *args, **kwargs)
    +def log(item, mark_pattern=None, *args, **kwargs):
    +    leveled_log = getattr(env.logging.logger, item.level.lower())
    +    return leveled_log(stylize_log(item, mark_pattern), *args, **kwargs)
     
     
    -def log_list(iterator):
    +def log_list(iterator, mark_pattern=None):
         any_logs = False
         for item in iterator:
    -        log(item)
    +        log(item, mark_pattern)
             any_logs = True
         return any_logs
    +
    +
    +def _find_pattern(pattern, field_value):
    +    # TODO: this finds the matching field type according to a pattern
    +    match = re.match(pattern, field_value)
    +    if match:
    +        return match.group(1)
    +
    +
    +def _get_format():
    +    return env.config.logging.formats[env.logging.verbosity_level]
    +
    +
    +def _styles(field_type):
    +    return env.config.logging.styles[field_type]
    +
    +
    +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():
    +    return Color.Schema(back=_styles(MARKER))
    +
    +
    +def _update_implementation(str_, implementation, log_item, mark_pattern=None):
    +    _stylize(str_, implementation, log_item, IMPLEMENTATION, mark_pattern)
    +
    +
    +def _update_inputs(str_, inputs, log_item, mark_pattern=None):
    +    _stylize(str_, inputs, log_item, INPUTS, mark_pattern)
    +
    +
    +def _update_timestamp(str_, timestamp, log_item):
    +    _stylize(str_, timestamp, log_item, TIMESTAMP)
    +
    +
    +def _update_message(str_, message, log_item, mark_pattern=None):
    +    _stylize(str_, message, log_item, MESSAGE, mark_pattern)
    +
    +
    +def _update_level(str_, log_item):
    +    _stylize(str_, log_item.level[0], log_item, LEVEL)
    +
    +
    +def _stylize(stylized_str, msg, log_item, msg_type, mark_pattern=None):
    +    matched_str = _find_pattern(_PATTERNS[FIELD_TYPE][msg_type], stylized_str._str)
    +    if not matched_str:
    +        return stylized_str
    +
    +    substring = Color.stylize(matched_str)
    +
    +    substring.format(**{msg_type: msg})
    +    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):
    +    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
    +
    +
    +def _end_execution_schema(log_item):
    +    if log_item.task:
    +        # This can't be an end workflow log
    +        return
    +    for state, pattern in _PATTERNS[FINAL_STATES].items():
    +        if re.match(pattern, log_item.msg):
    +            return _FINAL_STATES[state]
    +
    +
    +def _resolve_schema(msg_type, log_item):
    +    schema = _end_execution_schema(log_item)
    --- End diff --
    
    change name of function or its behavior


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] incubator-ariatosca pull request #109: ARIA-146-Support-colorful-execution-l...

Posted by mxmrlv <gi...@git.apache.org>.
Github user mxmrlv commented on a diff in the pull request:

    https://github.com/apache/incubator-ariatosca/pull/109#discussion_r113655141
  
    --- Diff: aria/cli/config/config_template.yaml ---
    @@ -10,3 +9,39 @@ logging:
     
         # main logger of the cli. provides basic descriptions for executed operations.
         aria.cli.main: info
    +
    +  execution:
    +    formats:
    +      # According to verbosity level 0 - no verbose. 3 - high verbose
    +      0: '{message}'
    +      1: '{timestamp:%H:%M:%S} | {level[0]} | {message}'
    +      2: '{timestamp:%H:%M:%S} | {level[0]} | {implementation} | {message}'
    +      3: '{timestamp:%H:%M:%S} | {level[0]} | {implementation} | {inputs} | {message}'
    +
    +    styles:
    +      enabled: true
    +
    +      level:
    --- End diff --
    
    move the changes to the code, and add default to each level


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] incubator-ariatosca pull request #109: ARIA-146-Support-colorful-execution-l...

Posted by mxmrlv <gi...@git.apache.org>.
Github user mxmrlv commented on a diff in the pull request:

    https://github.com/apache/incubator-ariatosca/pull/109#discussion_r113235649
  
    --- Diff: aria/cli/color.py ---
    @@ -0,0 +1,73 @@
    +# Licensed to the Apache Software Foundation (ASF) under one or more
    +# contributor license agreements.  See the NOTICE file distributed with
    +# this work for additional information regarding copyright ownership.
    +# The ASF licenses this file to You under the Apache License, Version 2.0
    +# (the "License"); you may not use this file except in compliance with
    +# the License.  You may obtain a copy of the License at
    +#
    +#     http://www.apache.org/licenses/LICENSE-2.0
    +#
    +# Unless required by applicable law or agreed to in writing, software
    +# distributed under the License is distributed on an "AS IS" BASIS,
    +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    +# See the License for the specific language governing permissions and
    +# limitations under the License.
    +from StringIO import StringIO
    +
    +import colorama
    +
    +colorama.init()
    +
    +
    +def _get_colors(color_type):
    +    for name in dir(color_type):
    +        if not name.startswith('_'):
    +            yield (name.lower(), getattr(color_type, name))
    +
    +
    +class Color(object):
    +    Fore = colorama.Fore
    +    Back = colorama.Back
    +    Style = colorama.Style
    +
    +    _colors = {
    +        'fore': dict(_get_colors(Fore)),
    +        'back': dict(_get_colors(Back)),
    +        'style': dict(_get_colors(Style))
    +    }
    +
    +    class Schema(object):
    +        def __init__(self, **kwargs):
    +            """
    +            It is possible to provide fore, back and style arguments. each could be either
    +            the color is lower case letter, or the actual color from colorama.
    +
    +            """
    +            assert all(arg in Color._colors for arg in kwargs)
    --- End diff --
    
    use itertools if necessary


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] incubator-ariatosca pull request #109: ARIA-146-Support-colorful-execution-l...

Posted by mxmrlv <gi...@git.apache.org>.
Github user mxmrlv commented on a diff in the pull request:

    https://github.com/apache/incubator-ariatosca/pull/109#discussion_r113234319
  
    --- Diff: aria/cli/execution_logging.py ---
    @@ -12,62 +12,208 @@
     # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     # See the License for the specific language governing permissions and
     # limitations under the License.
    -
    +import os
    +import re
     from StringIO import StringIO
    +from contextlib import contextmanager
     
     from . import logger
    +from .color import Color
     from .env import env
     
    +
    +LEVEL = 'level'
    +TIMESTAMP = 'timestamp'
    +MESSAGE = 'message'
    +IMPLEMENTATION = 'implementation'
    +INPUTS = 'inputs'
    +TRACEBACK = 'traceback'
    +MARKER = 'marker'
    +
    +FINAL_STATES = 'final_states'
    +SUCCESS_STATE = 'success'
    +CANCEL_STATE = 'cancel'
    +FAIL_STATE = 'fail'
    +
    +
    +_EXECUTION_BASE_PATTERN = "\'.*\' workflow execution "
    +_SUCCESSFUL_EXECUTION_PATTERN = _EXECUTION_BASE_PATTERN + "succeeded"
    +_FAILED_EXECUTION_PATTERN = _EXECUTION_BASE_PATTERN + "failed"
    +_CANCELED_EXECUTION_PATTERN = _EXECUTION_BASE_PATTERN + "canceled"
    +
     DEFAULT_FORMATTING = {
    -    logger.NO_VERBOSE: {'message': '{item.msg}'},
    +    logger.NO_VERBOSE: {'message': '{message}'},
         logger.LOW_VERBOSE: {
    -        'message': '{timestamp} | {item.level[0]} | {item.msg}',
    -        'timestamp': '%H:%M:%S'
    +        MESSAGE: '{timestamp} | {level} | {message}',
    +        LEVEL: '{level[0]}',
    +        TIMESTAMP: '%H:%M:%S',
         },
         logger.MEDIUM_VERBOSE: {
    -        'message': '{timestamp} | {item.level[0]} | {implementation} | {item.msg} ',
    -        'timestamp': '%H:%M:%S'
    +        MESSAGE: '{timestamp} | {level} | {implementation} | {message} ',
    +        LEVEL: '{level[0]}',
    +        TIMESTAMP: '%H:%M:%S'
         },
         logger.HIGH_VERBOSE: {
    -        'message': '{timestamp} | {item.level[0]} | {implementation}({inputs}) | {item.msg} ',
    -        'timestamp': '%H:%M:%S'
    +        MESSAGE: '{timestamp} | {level} | {implementation} | {inputs} | {message} ',
    +        LEVEL: '{level[0]}',
    +        TIMESTAMP: '%H:%M:%S'
    +    },
    +}
    +
    +DEFAULT_STYLING = {
    +    LEVEL: {
    +        'info': Color.Fore.LIGHTMAGENTA_EX,
    +        'debug': Color.Schema(fore=Color.Fore.LIGHTMAGENTA_EX, style=Color.Style.DIM),
    +        'error': Color.Schema(fore=Color.Fore.RED, style=Color.Style.BRIGHT),
         },
    +    TIMESTAMP: {
    +        'info': Color.Fore.LIGHTMAGENTA_EX,
    +        'debug': Color.Schema(fore=Color.Fore.LIGHTMAGENTA_EX, style=Color.Style.DIM),
    +        'error': Color.Schema(fore=Color.Fore.RED, style=Color.Style.BRIGHT),
    +    },
    +    MESSAGE: {
    +        'info': Color.Fore.LIGHTBLUE_EX,
    +        'debug': Color.Schema(fore=Color.Fore.LIGHTBLUE_EX, style=Color.Style.DIM),
    +        'error': Color.Schema(fore=Color.Fore.RED, style=Color.Style.BRIGHT),
    +    },
    +    IMPLEMENTATION: {
    +        'info': Color.Fore.LIGHTBLACK_EX,
    +        'debug': Color.Schema(fore=Color.Fore.LIGHTBLACK_EX, style=Color.Style.DIM),
    +        'error': Color.Schema(fore=Color.Fore.RED, style=Color.Style.BRIGHT),
    +    },
    +    INPUTS: {
    +        'info': Color.Fore.BLUE,
    +        'debug': Color.Schema(fore=Color.Fore.BLUE, style=Color.Style.DIM),
    +        'error': Color.Schema(fore=Color.Fore.RED, style=Color.Style.BRIGHT),
    +    },
    +    TRACEBACK: {'error': Color.Fore.RED},
    +
    +    MARKER: Color.Back.LIGHTYELLOW_EX,
    +    FINAL_STATES: {
    +        SUCCESS_STATE: Color.Fore.GREEN,
    +        CANCEL_STATE: Color.Fore.YELLOW,
    +        FAIL_STATE: Color.Fore.RED,
    +    }
     }
     
    +_PATTERNS = {
    +    SUCCESS_STATE: re.compile(_SUCCESSFUL_EXECUTION_PATTERN),
    +    CANCEL_STATE: re.compile(_CANCELED_EXECUTION_PATTERN),
    +    FAIL_STATE: re.compile(_FAILED_EXECUTION_PATTERN)
    +
    +}
    +
    +
    +class _StylizedLogs(object):
    +
    +    def __init__(self):
    +        self._formats = DEFAULT_FORMATTING
    +        self._styles = DEFAULT_STYLING
    +        self._mark_pattern = None
    +
    +    def _push(self, styles=None, formats=None, mark_pattern=None):
    --- End diff --
    
    remove


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] incubator-ariatosca pull request #109: ARIA-146-Support-colorful-execution-l...

Posted by mxmrlv <gi...@git.apache.org>.
Github user mxmrlv commented on a diff in the pull request:

    https://github.com/apache/incubator-ariatosca/pull/109#discussion_r113652814
  
    --- Diff: aria/cli/config/config.py ---
    @@ -71,3 +71,15 @@ def filename(self):
             @property
             def loggers(self):
                 return self._logging.get('loggers', {})
    +
    --- End diff --
    
    remove colors from config


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] incubator-ariatosca pull request #109: ARIA-146-Support-colorful-execution-l...

Posted by mxmrlv <gi...@git.apache.org>.
Github user mxmrlv commented on a diff in the pull request:

    https://github.com/apache/incubator-ariatosca/pull/109#discussion_r113680603
  
    --- Diff: aria/__init__.py ---
    @@ -60,9 +60,9 @@ def install_aria_extensions():
         for loader, module_name, _ in iter_modules():
             if module_name.startswith('aria_extension_'):
                 loader.find_module(module_name).load_module(module_name)
    -    if pkg_resources:
    -        for entry_point in pkg_resources.iter_entry_points(group='aria_extension'):
    -            entry_point.load()
    +    # if pkg_resources:
    --- End diff --
    
    revert


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] incubator-ariatosca pull request #109: ARIA-146-Support-colorful-execution-l...

Posted by mxmrlv <gi...@git.apache.org>.
Github user mxmrlv commented on a diff in the pull request:

    https://github.com/apache/incubator-ariatosca/pull/109#discussion_r113236673
  
    --- Diff: aria/cli/color.py ---
    @@ -0,0 +1,73 @@
    +# Licensed to the Apache Software Foundation (ASF) under one or more
    +# contributor license agreements.  See the NOTICE file distributed with
    +# this work for additional information regarding copyright ownership.
    +# The ASF licenses this file to You under the Apache License, Version 2.0
    +# (the "License"); you may not use this file except in compliance with
    +# the License.  You may obtain a copy of the License at
    +#
    +#     http://www.apache.org/licenses/LICENSE-2.0
    +#
    +# Unless required by applicable law or agreed to in writing, software
    +# distributed under the License is distributed on an "AS IS" BASIS,
    +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    +# See the License for the specific language governing permissions and
    +# limitations under the License.
    +from StringIO import StringIO
    +
    +import colorama
    +
    +colorama.init()
    +
    +
    +def _get_colors(color_type):
    +    for name in dir(color_type):
    +        if not name.startswith('_'):
    +            yield (name.lower(), getattr(color_type, name))
    +
    +
    +class Color(object):
    +    Fore = colorama.Fore
    +    Back = colorama.Back
    +    Style = colorama.Style
    +
    +    _colors = {
    +        'fore': dict(_get_colors(Fore)),
    +        'back': dict(_get_colors(Back)),
    +        'style': dict(_get_colors(Style))
    +    }
    +
    +    class Schema(object):
    +        def __init__(self, **kwargs):
    +            """
    +            It is possible to provide fore, back and style arguments. each could be either
    +            the color is lower case letter, or the actual color from colorama.
    +
    +            """
    +            assert all(arg in Color._colors for arg in kwargs)
    +            self._kwargs = kwargs
    +            self._str = StringIO()
    +            for type_, colors in Color._colors.items():
    +                value = kwargs.pop(type_, None)
    +                # the former case is if the value is a string, the latter is in case of an object.
    +                self._str.write(colors.get(value) or value)
    +
    +        def __str__(self):
    +            return self._str.getvalue()
    +
    +        def __add__(self, other):
    +            return str(self) + str(other)
    +
    +        def __radd__(self, other):
    +            return str(other) + str(self)
    +
    +    @classmethod
    +    def stylize(cls, str_to_stylize, schema):
    +        return schema + str(str_to_stylize) + cls.Style.RESET_ALL
    +
    +    @classmethod
    +    def markup(cls, str_to_stylize, matches, schema):
    +        modified_str = str_to_stylize
    --- End diff --
    
    stay with original parameter?


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] incubator-ariatosca pull request #109: ARIA-146-Support-colorful-execution-l...

Posted by mxmrlv <gi...@git.apache.org>.
Github user mxmrlv commented on a diff in the pull request:

    https://github.com/apache/incubator-ariatosca/pull/109#discussion_r113681303
  
    --- Diff: aria/cli/color.py ---
    @@ -70,29 +70,26 @@ class Color(object):
             'style': dict(_get_colors(Style))
         }
     
    -    class Schema(object):
    -        def __init__(self, fore=None, back=None, style=None):
    -            """
    -            It is possible to provide fore, back and style arguments. each could be either
    -            the color is lower case letter, or the actual color from colorama.
     
    -            """
    -            self._kwargs = dict(fore=fore, back=back, style=style)
    -            self._str = StringIO()
    -            for type_, colors in Color._colors.items():
    -                value = self._kwargs.get(type_, None)
    -                # the former case is if the value is a string, the latter is in case of an object.
    -                self._str.write(colors.get(value) or value)
    +class Schema(object):
    --- End diff --
    
    ColorSpec


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] incubator-ariatosca pull request #109: ARIA-146-Support-colorful-execution-l...

Posted by mxmrlv <gi...@git.apache.org>.
Github user mxmrlv commented on a diff in the pull request:

    https://github.com/apache/incubator-ariatosca/pull/109#discussion_r113237789
  
    --- Diff: aria/cli/color.py ---
    @@ -0,0 +1,73 @@
    +# Licensed to the Apache Software Foundation (ASF) under one or more
    +# contributor license agreements.  See the NOTICE file distributed with
    +# this work for additional information regarding copyright ownership.
    +# The ASF licenses this file to You under the Apache License, Version 2.0
    +# (the "License"); you may not use this file except in compliance with
    +# the License.  You may obtain a copy of the License at
    +#
    +#     http://www.apache.org/licenses/LICENSE-2.0
    +#
    +# Unless required by applicable law or agreed to in writing, software
    +# distributed under the License is distributed on an "AS IS" BASIS,
    +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    +# See the License for the specific language governing permissions and
    +# limitations under the License.
    +from StringIO import StringIO
    +
    +import colorama
    +
    +colorama.init()
    +
    +
    +def _get_colors(color_type):
    +    for name in dir(color_type):
    +        if not name.startswith('_'):
    +            yield (name.lower(), getattr(color_type, name))
    +
    +
    +class Color(object):
    +    Fore = colorama.Fore
    +    Back = colorama.Back
    +    Style = colorama.Style
    +
    +    _colors = {
    +        'fore': dict(_get_colors(Fore)),
    +        'back': dict(_get_colors(Back)),
    +        'style': dict(_get_colors(Style))
    +    }
    +
    +    class Schema(object):
    +        def __init__(self, **kwargs):
    +            """
    +            It is possible to provide fore, back and style arguments. each could be either
    +            the color is lower case letter, or the actual color from colorama.
    +
    +            """
    +            assert all(arg in Color._colors for arg in kwargs)
    +            self._kwargs = kwargs
    +            self._str = StringIO()
    +            for type_, colors in Color._colors.items():
    +                value = kwargs.pop(type_, None)
    +                # the former case is if the value is a string, the latter is in case of an object.
    +                self._str.write(colors.get(value) or value)
    +
    +        def __str__(self):
    +            return self._str.getvalue()
    +
    +        def __add__(self, other):
    +            return str(self) + str(other)
    +
    +        def __radd__(self, other):
    +            return str(other) + str(self)
    +
    +    @classmethod
    +    def stylize(cls, str_to_stylize, schema):
    +        return schema + str(str_to_stylize) + cls.Style.RESET_ALL
    +
    +    @classmethod
    +    def markup(cls, str_to_stylize, matches, schema):
    +        modified_str = str_to_stylize
    +        for group_index in xrange(len(matches.regs)):
    +            match = matches.group(group_index)
    +            modified_str = modified_str.replace(match, schema + match + cls.Back.RESET)
    --- End diff --
    
    consider using stylize


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] incubator-ariatosca pull request #109: ARIA-146-Support-colorful-execution-l...

Posted by mxmrlv <gi...@git.apache.org>.
Github user mxmrlv commented on a diff in the pull request:

    https://github.com/apache/incubator-ariatosca/pull/109#discussion_r113657554
  
    --- Diff: aria/cli/execution_logging.py ---
    @@ -12,67 +12,228 @@
     # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     # See the License for the specific language governing permissions and
     # limitations under the License.
    -
    +import os
    +import re
     from StringIO import StringIO
     
     from . import logger
    +from .color import Color
     from .env import env
     
    -DEFAULT_FORMATTING = {
    -    logger.NO_VERBOSE: {'message': '{item.msg}'},
    -    logger.LOW_VERBOSE: {
    -        'message': '{timestamp} | {item.level[0]} | {item.msg}',
    -        'timestamp': '%H:%M:%S'
    +
    +FIELD_TYPE = 'field_type'
    +LEVEL = 'level'
    +TIMESTAMP = 'timestamp'
    +MESSAGE = 'message'
    +IMPLEMENTATION = 'implementation'
    +INPUTS = 'inputs'
    +TRACEBACK = 'traceback'
    +MARKER = 'marker'
    +
    +FINAL_STATES = 'final_states'
    +SUCCESS_STATE = 'success'
    +CANCEL_STATE = 'cancel'
    +FAIL_STATE = 'fail'
    +
    +_EXECUTION_BASE_PATTERN = "\'.*\' workflow execution "
    +_SUCCESSFUL_EXECUTION_PATTERN = _EXECUTION_BASE_PATTERN + "succeeded"
    +_FAILED_EXECUTION_PATTERN = _EXECUTION_BASE_PATTERN + "failed"
    +_CANCELED_EXECUTION_PATTERN = _EXECUTION_BASE_PATTERN + "canceled"
    +
    +_TIMESTAMP_PATTERN = '.*({timestamp.*?}).*'
    +_LEVEL_PATTERN = '.*({level.*?}).*'
    +_MESSAGE_PATTERN = '.*({message.*?}).*'
    +_IMPLEMENTATION_PATTERN = '.*({implementation.*?}).*'
    +_INPUTS_PATTERN = '.*({inputs.*?}).*'
    +
    +_PATTERNS = {
    +    FINAL_STATES: {
    +        SUCCESS_STATE: re.compile(_SUCCESSFUL_EXECUTION_PATTERN),
    +        CANCEL_STATE: re.compile(_CANCELED_EXECUTION_PATTERN),
    +        FAIL_STATE: re.compile(_FAILED_EXECUTION_PATTERN),
         },
    -    logger.MEDIUM_VERBOSE: {
    -        'message': '{timestamp} | {item.level[0]} | {implementation} | {item.msg} ',
    -        'timestamp': '%H:%M:%S'
    +    FIELD_TYPE: {
    +        IMPLEMENTATION: re.compile(_IMPLEMENTATION_PATTERN),
    +        LEVEL: re.compile(_LEVEL_PATTERN),
    +        MESSAGE: re.compile(_MESSAGE_PATTERN),
    +        INPUTS: re.compile(_INPUTS_PATTERN),
    +        TIMESTAMP: re.compile(_TIMESTAMP_PATTERN)
    +    }
    +}
    +
    +_FINAL_STATES = {
    +    SUCCESS_STATE: Color.Fore.GREEN,
    +    CANCEL_STATE: Color.Fore.YELLOW,
    +    FAIL_STATE: Color.Fore.RED
    +}
    +
    +_DEFAULT_STYLE = {
    +    LEVEL: {
    +        'info': {'fore': 'lightmagenta_ex'},
    +        'debug': {'fore': 'lightmagenta_ex', 'style': 'dim'},
    +        'error': {'fore': 'red', 'style': 'bright'},
         },
    -    logger.HIGH_VERBOSE: {
    -        'message': '{timestamp} | {item.level[0]} | {implementation}({inputs}) | {item.msg} ',
    -        'timestamp': '%H:%M:%S'
    +    TIMESTAMP: {
    +        'info': {'fore': 'lightmagenta_ex'},
    +        'debug': {'fore': 'lightmagenta_ex', 'style': 'dim'},
    +        'error': {'fore': 'red', 'style': 'bright'},
         },
    -}
    +    MESSAGE: {
    +        'info': {'fore': 'lightblue_ex'},
    +        'debug': {'fore': 'lightblue_ex', 'style': 'dim'},
    +        'error': {'fore': 'red', 'style': 'bright'},
    +    },
    +    IMPLEMENTATION:{
    +        'info': {'fore': 'lightblack_ex'},
    +        'debug': {'fore': 'lightblack_ex', 'style': 'dim'},
    +        'error': {'fore': 'red', 'style': 'bright'},
    +    },
    +    INPUTS: {
    +        'info': {'fore': 'blue'},
    +        'debug': {'fore': 'blue', 'style': 'dim'},
    +        'error': {'fore': 'red', 'style': 'bright'},
    +    },
    +    TRACEBACK: {'error': {'fore': 'red'}},
     
    +    MARKER: 'lightyellow_ex'
    +}
     
    -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)
    +def stylize_log(item, mark_pattern):
     
    +    # implementation
         if item.task:
    -        formatting_kwargs['implementation'] = item.task.implementation
    -        formatting_kwargs['inputs'] = dict(i.unwrap() for i in item.task.inputs.values())
    +        # operation task
    +        implementation = item.task.implementation
    +        inputs = dict(i.unwrap() for i in item.task.inputs.values())
         else:
    -        formatting_kwargs['implementation'] = item.execution.workflow_name
    -        formatting_kwargs['inputs'] = dict(i.unwrap() for i in item.execution.inputs.values())
    +        # execution task
    +        implementation = item.execution.workflow_name
    +        inputs = dict(i.unwrap() for i in item.execution.inputs.values())
     
    -    if 'timestamp' in formatting:
    -        formatting_kwargs['timestamp'] = item.created_at.strftime(formatting['timestamp'])
    -    else:
    -        formatting_kwargs['timestamp'] = item.created_at
    -
    -    msg.write(formatting['message'].format(**formatting_kwargs))
    +    # TODO: use the is_workflow_log
    +    stylized_str = Color.stylize(_get_format())
    +    _update_level(stylized_str, item)
    +    _update_timestamp(stylized_str, item.created_at, item)
    +    _update_message(stylized_str, item.msg, item, mark_pattern)
    +    _update_inputs(stylized_str, inputs, item, mark_pattern)
    +    _update_implementation(stylized_str, implementation, item, mark_pattern)
     
    +    msg = StringIO()
    +    msg.write(str(stylized_str))
         # Add the exception and the error msg.
         if item.traceback and env.logging.verbosity_level >= logger.MEDIUM_VERBOSE:
    -        for line in item.traceback.splitlines(True):
    -            msg.write('\t' + '|' + line)
    +        msg.write(os.linesep)
    +        msg.writelines(_get_traceback('\t' + '|' + line, item, mark_pattern)
    +                       for line in item.traceback.splitlines(True))
     
         return msg.getvalue()
     
     
    -def log(item, *args, **kwargs):
    -    return getattr(env.logging.logger, item.level.lower())(_str(item), *args, **kwargs)
    +def log(item, mark_pattern=None, *args, **kwargs):
    +    leveled_log = getattr(env.logging.logger, item.level.lower())
    +    return leveled_log(stylize_log(item, mark_pattern), *args, **kwargs)
     
     
    -def log_list(iterator):
    +def log_list(iterator, mark_pattern=None):
         any_logs = False
         for item in iterator:
    -        log(item)
    +        log(item, mark_pattern)
             any_logs = True
         return any_logs
    +
    +
    +def _find_pattern(pattern, field_value):
    +    # TODO: this finds the matching field type according to a pattern
    +    match = re.match(pattern, field_value)
    +    if match:
    +        return match.group(1)
    +
    +
    +def _get_format():
    +    return env.config.logging.formats[env.logging.verbosity_level]
    +
    +
    +def _styles(field_type):
    +    return env.config.logging.styles[field_type]
    +
    +
    +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():
    +    return Color.Schema(back=_styles(MARKER))
    +
    +
    +def _update_implementation(str_, implementation, log_item, mark_pattern=None):
    +    _stylize(str_, implementation, log_item, IMPLEMENTATION, mark_pattern)
    +
    +
    +def _update_inputs(str_, inputs, log_item, mark_pattern=None):
    +    _stylize(str_, inputs, log_item, INPUTS, mark_pattern)
    +
    +
    +def _update_timestamp(str_, timestamp, log_item):
    +    _stylize(str_, timestamp, log_item, TIMESTAMP)
    +
    +
    +def _update_message(str_, message, log_item, mark_pattern=None):
    +    _stylize(str_, message, log_item, MESSAGE, mark_pattern)
    +
    +
    +def _update_level(str_, log_item):
    +    _stylize(str_, log_item.level[0], log_item, LEVEL)
    +
    +
    +def _stylize(stylized_str, msg, log_item, msg_type, mark_pattern=None):
    +    matched_str = _find_pattern(_PATTERNS[FIELD_TYPE][msg_type], stylized_str._str)
    +    if not matched_str:
    +        return stylized_str
    +
    +    substring = Color.stylize(matched_str)
    +
    +    substring.format(**{msg_type: msg})
    +    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):
    --- End diff --
    
    color traceback


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] incubator-ariatosca pull request #109: ARIA-146-Support-colorful-execution-l...

Posted by mxmrlv <gi...@git.apache.org>.
Github user mxmrlv commented on a diff in the pull request:

    https://github.com/apache/incubator-ariatosca/pull/109#discussion_r113227856
  
    --- Diff: aria/cli/execution_logging.py ---
    @@ -12,62 +12,208 @@
     # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     # See the License for the specific language governing permissions and
     # limitations under the License.
    -
    +import os
    +import re
     from StringIO import StringIO
    +from contextlib import contextmanager
     
     from . import logger
    +from .color import Color
     from .env import env
     
    +
    +LEVEL = 'level'
    +TIMESTAMP = 'timestamp'
    +MESSAGE = 'message'
    +IMPLEMENTATION = 'implementation'
    +INPUTS = 'inputs'
    +TRACEBACK = 'traceback'
    +MARKER = 'marker'
    +
    +FINAL_STATES = 'final_states'
    +SUCCESS_STATE = 'success'
    +CANCEL_STATE = 'cancel'
    +FAIL_STATE = 'fail'
    +
    +
    +_EXECUTION_BASE_PATTERN = "\'.*\' workflow execution "
    +_SUCCESSFUL_EXECUTION_PATTERN = _EXECUTION_BASE_PATTERN + "succeeded"
    +_FAILED_EXECUTION_PATTERN = _EXECUTION_BASE_PATTERN + "failed"
    +_CANCELED_EXECUTION_PATTERN = _EXECUTION_BASE_PATTERN + "canceled"
    +
     DEFAULT_FORMATTING = {
    -    logger.NO_VERBOSE: {'message': '{item.msg}'},
    +    logger.NO_VERBOSE: {'message': '{message}'},
         logger.LOW_VERBOSE: {
    -        'message': '{timestamp} | {item.level[0]} | {item.msg}',
    -        'timestamp': '%H:%M:%S'
    +        MESSAGE: '{timestamp} | {level} | {message}',
    +        LEVEL: '{level[0]}',
    +        TIMESTAMP: '%H:%M:%S',
         },
         logger.MEDIUM_VERBOSE: {
    -        'message': '{timestamp} | {item.level[0]} | {implementation} | {item.msg} ',
    -        'timestamp': '%H:%M:%S'
    +        MESSAGE: '{timestamp} | {level} | {implementation} | {message} ',
    +        LEVEL: '{level[0]}',
    +        TIMESTAMP: '%H:%M:%S'
         },
         logger.HIGH_VERBOSE: {
    -        'message': '{timestamp} | {item.level[0]} | {implementation}({inputs}) | {item.msg} ',
    -        'timestamp': '%H:%M:%S'
    +        MESSAGE: '{timestamp} | {level} | {implementation} | {inputs} | {message} ',
    +        LEVEL: '{level[0]}',
    +        TIMESTAMP: '%H:%M:%S'
    +    },
    +}
    +
    +DEFAULT_STYLING = {
    +    LEVEL: {
    +        'info': Color.Fore.LIGHTMAGENTA_EX,
    +        'debug': Color.Schema(fore=Color.Fore.LIGHTMAGENTA_EX, style=Color.Style.DIM),
    +        'error': Color.Schema(fore=Color.Fore.RED, style=Color.Style.BRIGHT),
         },
    +    TIMESTAMP: {
    +        'info': Color.Fore.LIGHTMAGENTA_EX,
    +        'debug': Color.Schema(fore=Color.Fore.LIGHTMAGENTA_EX, style=Color.Style.DIM),
    +        'error': Color.Schema(fore=Color.Fore.RED, style=Color.Style.BRIGHT),
    +    },
    +    MESSAGE: {
    +        'info': Color.Fore.LIGHTBLUE_EX,
    +        'debug': Color.Schema(fore=Color.Fore.LIGHTBLUE_EX, style=Color.Style.DIM),
    +        'error': Color.Schema(fore=Color.Fore.RED, style=Color.Style.BRIGHT),
    +    },
    +    IMPLEMENTATION: {
    +        'info': Color.Fore.LIGHTBLACK_EX,
    +        'debug': Color.Schema(fore=Color.Fore.LIGHTBLACK_EX, style=Color.Style.DIM),
    +        'error': Color.Schema(fore=Color.Fore.RED, style=Color.Style.BRIGHT),
    +    },
    +    INPUTS: {
    +        'info': Color.Fore.BLUE,
    +        'debug': Color.Schema(fore=Color.Fore.BLUE, style=Color.Style.DIM),
    +        'error': Color.Schema(fore=Color.Fore.RED, style=Color.Style.BRIGHT),
    +    },
    +    TRACEBACK: {'error': Color.Fore.RED},
    +
    +    MARKER: Color.Back.LIGHTYELLOW_EX,
    +    FINAL_STATES: {
    +        SUCCESS_STATE: Color.Fore.GREEN,
    +        CANCEL_STATE: Color.Fore.YELLOW,
    +        FAIL_STATE: Color.Fore.RED,
    +    }
     }
     
    +_PATTERNS = {
    --- End diff --
    
    consider also checking log for whether its task related or workflow related


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] incubator-ariatosca pull request #109: ARIA-146-Support-colorful-execution-l...

Posted by mxmrlv <gi...@git.apache.org>.
Github user mxmrlv commented on a diff in the pull request:

    https://github.com/apache/incubator-ariatosca/pull/109#discussion_r113226725
  
    --- Diff: aria/cli/execution_logging.py ---
    @@ -12,62 +12,208 @@
     # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     # See the License for the specific language governing permissions and
     # limitations under the License.
    -
    +import os
    +import re
     from StringIO import StringIO
    +from contextlib import contextmanager
     
     from . import logger
    +from .color import Color
     from .env import env
     
    +
    +LEVEL = 'level'
    +TIMESTAMP = 'timestamp'
    +MESSAGE = 'message'
    +IMPLEMENTATION = 'implementation'
    +INPUTS = 'inputs'
    +TRACEBACK = 'traceback'
    +MARKER = 'marker'
    +
    +FINAL_STATES = 'final_states'
    +SUCCESS_STATE = 'success'
    +CANCEL_STATE = 'cancel'
    +FAIL_STATE = 'fail'
    +
    +
    +_EXECUTION_BASE_PATTERN = "\'.*\' workflow execution "
    +_SUCCESSFUL_EXECUTION_PATTERN = _EXECUTION_BASE_PATTERN + "succeeded"
    +_FAILED_EXECUTION_PATTERN = _EXECUTION_BASE_PATTERN + "failed"
    +_CANCELED_EXECUTION_PATTERN = _EXECUTION_BASE_PATTERN + "canceled"
    +
     DEFAULT_FORMATTING = {
    -    logger.NO_VERBOSE: {'message': '{item.msg}'},
    +    logger.NO_VERBOSE: {'message': '{message}'},
         logger.LOW_VERBOSE: {
    -        'message': '{timestamp} | {item.level[0]} | {item.msg}',
    -        'timestamp': '%H:%M:%S'
    +        MESSAGE: '{timestamp} | {level} | {message}',
    +        LEVEL: '{level[0]}',
    +        TIMESTAMP: '%H:%M:%S',
         },
         logger.MEDIUM_VERBOSE: {
    -        'message': '{timestamp} | {item.level[0]} | {implementation} | {item.msg} ',
    -        'timestamp': '%H:%M:%S'
    +        MESSAGE: '{timestamp} | {level} | {implementation} | {message} ',
    +        LEVEL: '{level[0]}',
    +        TIMESTAMP: '%H:%M:%S'
         },
         logger.HIGH_VERBOSE: {
    -        'message': '{timestamp} | {item.level[0]} | {implementation}({inputs}) | {item.msg} ',
    -        'timestamp': '%H:%M:%S'
    +        MESSAGE: '{timestamp} | {level} | {implementation} | {inputs} | {message} ',
    +        LEVEL: '{level[0]}',
    +        TIMESTAMP: '%H:%M:%S'
    +    },
    +}
    +
    +DEFAULT_STYLING = {
    +    LEVEL: {
    +        'info': Color.Fore.LIGHTMAGENTA_EX,
    +        'debug': Color.Schema(fore=Color.Fore.LIGHTMAGENTA_EX, style=Color.Style.DIM),
    +        'error': Color.Schema(fore=Color.Fore.RED, style=Color.Style.BRIGHT),
         },
    +    TIMESTAMP: {
    --- End diff --
    
    1) support default in case user doesnt provide
    2) have 'default' log level coloring


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] incubator-ariatosca pull request #109: ARIA-146-Support-colorful-execution-l...

Posted by mxmrlv <gi...@git.apache.org>.
Github user mxmrlv commented on a diff in the pull request:

    https://github.com/apache/incubator-ariatosca/pull/109#discussion_r113235566
  
    --- Diff: aria/cli/color.py ---
    @@ -0,0 +1,73 @@
    +# Licensed to the Apache Software Foundation (ASF) under one or more
    +# contributor license agreements.  See the NOTICE file distributed with
    +# this work for additional information regarding copyright ownership.
    +# The ASF licenses this file to You under the Apache License, Version 2.0
    +# (the "License"); you may not use this file except in compliance with
    +# the License.  You may obtain a copy of the License at
    +#
    +#     http://www.apache.org/licenses/LICENSE-2.0
    +#
    +# Unless required by applicable law or agreed to in writing, software
    +# distributed under the License is distributed on an "AS IS" BASIS,
    +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    +# See the License for the specific language governing permissions and
    +# limitations under the License.
    +from StringIO import StringIO
    +
    +import colorama
    +
    +colorama.init()
    +
    +
    +def _get_colors(color_type):
    +    for name in dir(color_type):
    +        if not name.startswith('_'):
    +            yield (name.lower(), getattr(color_type, name))
    +
    +
    +class Color(object):
    +    Fore = colorama.Fore
    +    Back = colorama.Back
    +    Style = colorama.Style
    +
    +    _colors = {
    +        'fore': dict(_get_colors(Fore)),
    +        'back': dict(_get_colors(Back)),
    +        'style': dict(_get_colors(Style))
    +    }
    +
    +    class Schema(object):
    +        def __init__(self, **kwargs):
    --- End diff --
    
    extract kwargs


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] incubator-ariatosca pull request #109: ARIA-146-Support-colorful-execution-l...

Posted by mxmrlv <gi...@git.apache.org>.
Github user mxmrlv commented on a diff in the pull request:

    https://github.com/apache/incubator-ariatosca/pull/109#discussion_r113652200
  
    --- Diff: aria/cli/color.py ---
    @@ -0,0 +1,98 @@
    +# Licensed to the Apache Software Foundation (ASF) under one or more
    +# contributor license agreements.  See the NOTICE file distributed with
    +# this work for additional information regarding copyright ownership.
    +# The ASF licenses this file to You under the Apache License, Version 2.0
    +# (the "License"); you may not use this file except in compliance with
    +# the License.  You may obtain a copy of the License at
    +#
    +#     http://www.apache.org/licenses/LICENSE-2.0
    +#
    +# Unless required by applicable law or agreed to in writing, software
    +# distributed under the License is distributed on an "AS IS" BASIS,
    +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    +# See the License for the specific language governing permissions and
    +# limitations under the License.
    +from StringIO import StringIO
    +import re
    +
    +import colorama
    +
    +colorama.init()
    +
    +
    +def _get_colors(color_type):
    --- End diff --
    
    make static in class


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] incubator-ariatosca pull request #109: ARIA-146-Support-colorful-execution-l...

Posted by mxmrlv <gi...@git.apache.org>.
Github user mxmrlv commented on a diff in the pull request:

    https://github.com/apache/incubator-ariatosca/pull/109#discussion_r113681751
  
    --- Diff: aria/cli/execution_logging.py ---
    @@ -31,73 +34,67 @@
     MARKER = 'marker'
     
     FINAL_STATES = 'final_states'
    -SUCCESS_STATE = 'success'
    -CANCEL_STATE = 'cancel'
    -FAIL_STATE = 'fail'
    +SUCCESS_STATE = 'succeeded'
    +CANCEL_STATE = 'canceled'
    +FAIL_STATE = 'failed'
     
    -_EXECUTION_BASE_PATTERN = "\'.*\' workflow execution "
    -_SUCCESSFUL_EXECUTION_PATTERN = _EXECUTION_BASE_PATTERN + "succeeded"
    -_FAILED_EXECUTION_PATTERN = _EXECUTION_BASE_PATTERN + "failed"
    -_CANCELED_EXECUTION_PATTERN = _EXECUTION_BASE_PATTERN + "canceled"
    -
    -_TIMESTAMP_PATTERN = '.*({timestamp.*?}).*'
    -_LEVEL_PATTERN = '.*({level.*?}).*'
    -_MESSAGE_PATTERN = '.*({message.*?}).*'
    -_IMPLEMENTATION_PATTERN = '.*({implementation.*?}).*'
    -_INPUTS_PATTERN = '.*({inputs.*?}).*'
    +_EXECUTION_PATTERN = "\'.*\' workflow execution {0}".format
    +_FIELD_TYPE_PATTERN = partial('.*({starting}{0}{closing}).*'.format, starting='{', closing='.*?}')
    --- End diff --
    
    comment


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] incubator-ariatosca pull request #109: ARIA-146-Support-colorful-execution-l...

Posted by mxmrlv <gi...@git.apache.org>.
Github user mxmrlv commented on a diff in the pull request:

    https://github.com/apache/incubator-ariatosca/pull/109#discussion_r113659249
  
    --- Diff: aria/cli/execution_logging.py ---
    @@ -12,67 +12,228 @@
     # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     # See the License for the specific language governing permissions and
     # limitations under the License.
    -
    +import os
    +import re
     from StringIO import StringIO
     
     from . import logger
    +from .color import Color
     from .env import env
     
    -DEFAULT_FORMATTING = {
    -    logger.NO_VERBOSE: {'message': '{item.msg}'},
    -    logger.LOW_VERBOSE: {
    -        'message': '{timestamp} | {item.level[0]} | {item.msg}',
    -        'timestamp': '%H:%M:%S'
    +
    +FIELD_TYPE = 'field_type'
    +LEVEL = 'level'
    +TIMESTAMP = 'timestamp'
    +MESSAGE = 'message'
    +IMPLEMENTATION = 'implementation'
    +INPUTS = 'inputs'
    +TRACEBACK = 'traceback'
    +MARKER = 'marker'
    +
    +FINAL_STATES = 'final_states'
    +SUCCESS_STATE = 'success'
    +CANCEL_STATE = 'cancel'
    +FAIL_STATE = 'fail'
    +
    +_EXECUTION_BASE_PATTERN = "\'.*\' workflow execution "
    +_SUCCESSFUL_EXECUTION_PATTERN = _EXECUTION_BASE_PATTERN + "succeeded"
    +_FAILED_EXECUTION_PATTERN = _EXECUTION_BASE_PATTERN + "failed"
    +_CANCELED_EXECUTION_PATTERN = _EXECUTION_BASE_PATTERN + "canceled"
    +
    +_TIMESTAMP_PATTERN = '.*({timestamp.*?}).*'
    +_LEVEL_PATTERN = '.*({level.*?}).*'
    +_MESSAGE_PATTERN = '.*({message.*?}).*'
    +_IMPLEMENTATION_PATTERN = '.*({implementation.*?}).*'
    +_INPUTS_PATTERN = '.*({inputs.*?}).*'
    +
    +_PATTERNS = {
    +    FINAL_STATES: {
    +        SUCCESS_STATE: re.compile(_SUCCESSFUL_EXECUTION_PATTERN),
    +        CANCEL_STATE: re.compile(_CANCELED_EXECUTION_PATTERN),
    +        FAIL_STATE: re.compile(_FAILED_EXECUTION_PATTERN),
         },
    -    logger.MEDIUM_VERBOSE: {
    -        'message': '{timestamp} | {item.level[0]} | {implementation} | {item.msg} ',
    -        'timestamp': '%H:%M:%S'
    +    FIELD_TYPE: {
    +        IMPLEMENTATION: re.compile(_IMPLEMENTATION_PATTERN),
    +        LEVEL: re.compile(_LEVEL_PATTERN),
    +        MESSAGE: re.compile(_MESSAGE_PATTERN),
    +        INPUTS: re.compile(_INPUTS_PATTERN),
    +        TIMESTAMP: re.compile(_TIMESTAMP_PATTERN)
    +    }
    +}
    +
    +_FINAL_STATES = {
    +    SUCCESS_STATE: Color.Fore.GREEN,
    +    CANCEL_STATE: Color.Fore.YELLOW,
    +    FAIL_STATE: Color.Fore.RED
    +}
    +
    +_DEFAULT_STYLE = {
    +    LEVEL: {
    +        'info': {'fore': 'lightmagenta_ex'},
    +        'debug': {'fore': 'lightmagenta_ex', 'style': 'dim'},
    +        'error': {'fore': 'red', 'style': 'bright'},
         },
    -    logger.HIGH_VERBOSE: {
    -        'message': '{timestamp} | {item.level[0]} | {implementation}({inputs}) | {item.msg} ',
    -        'timestamp': '%H:%M:%S'
    +    TIMESTAMP: {
    +        'info': {'fore': 'lightmagenta_ex'},
    +        'debug': {'fore': 'lightmagenta_ex', 'style': 'dim'},
    +        'error': {'fore': 'red', 'style': 'bright'},
         },
    -}
    +    MESSAGE: {
    +        'info': {'fore': 'lightblue_ex'},
    +        'debug': {'fore': 'lightblue_ex', 'style': 'dim'},
    +        'error': {'fore': 'red', 'style': 'bright'},
    +    },
    +    IMPLEMENTATION:{
    +        'info': {'fore': 'lightblack_ex'},
    +        'debug': {'fore': 'lightblack_ex', 'style': 'dim'},
    +        'error': {'fore': 'red', 'style': 'bright'},
    +    },
    +    INPUTS: {
    +        'info': {'fore': 'blue'},
    +        'debug': {'fore': 'blue', 'style': 'dim'},
    +        'error': {'fore': 'red', 'style': 'bright'},
    +    },
    +    TRACEBACK: {'error': {'fore': 'red'}},
     
    +    MARKER: 'lightyellow_ex'
    +}
     
    -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)
    +def stylize_log(item, mark_pattern):
     
    +    # implementation
         if item.task:
    -        formatting_kwargs['implementation'] = item.task.implementation
    -        formatting_kwargs['inputs'] = dict(i.unwrap() for i in item.task.inputs.values())
    +        # operation task
    +        implementation = item.task.implementation
    +        inputs = dict(i.unwrap() for i in item.task.inputs.values())
         else:
    -        formatting_kwargs['implementation'] = item.execution.workflow_name
    -        formatting_kwargs['inputs'] = dict(i.unwrap() for i in item.execution.inputs.values())
    +        # execution task
    +        implementation = item.execution.workflow_name
    +        inputs = dict(i.unwrap() for i in item.execution.inputs.values())
     
    -    if 'timestamp' in formatting:
    -        formatting_kwargs['timestamp'] = item.created_at.strftime(formatting['timestamp'])
    -    else:
    -        formatting_kwargs['timestamp'] = item.created_at
    -
    -    msg.write(formatting['message'].format(**formatting_kwargs))
    +    # TODO: use the is_workflow_log
    +    stylized_str = Color.stylize(_get_format())
    +    _update_level(stylized_str, item)
    +    _update_timestamp(stylized_str, item.created_at, item)
    +    _update_message(stylized_str, item.msg, item, mark_pattern)
    +    _update_inputs(stylized_str, inputs, item, mark_pattern)
    +    _update_implementation(stylized_str, implementation, item, mark_pattern)
     
    +    msg = StringIO()
    +    msg.write(str(stylized_str))
         # Add the exception and the error msg.
         if item.traceback and env.logging.verbosity_level >= logger.MEDIUM_VERBOSE:
    -        for line in item.traceback.splitlines(True):
    -            msg.write('\t' + '|' + line)
    +        msg.write(os.linesep)
    +        msg.writelines(_get_traceback('\t' + '|' + line, item, mark_pattern)
    +                       for line in item.traceback.splitlines(True))
     
         return msg.getvalue()
     
     
    -def log(item, *args, **kwargs):
    -    return getattr(env.logging.logger, item.level.lower())(_str(item), *args, **kwargs)
    +def log(item, mark_pattern=None, *args, **kwargs):
    +    leveled_log = getattr(env.logging.logger, item.level.lower())
    +    return leveled_log(stylize_log(item, mark_pattern), *args, **kwargs)
     
     
    -def log_list(iterator):
    +def log_list(iterator, mark_pattern=None):
         any_logs = False
         for item in iterator:
    -        log(item)
    +        log(item, mark_pattern)
             any_logs = True
         return any_logs
    +
    +
    +def _find_pattern(pattern, field_value):
    +    # TODO: this finds the matching field type according to a pattern
    +    match = re.match(pattern, field_value)
    +    if match:
    +        return match.group(1)
    +
    +
    +def _get_format():
    +    return env.config.logging.formats[env.logging.verbosity_level]
    +
    +
    +def _styles(field_type):
    +    return env.config.logging.styles[field_type]
    +
    +
    +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():
    +    return Color.Schema(back=_styles(MARKER))
    +
    +
    +def _update_implementation(str_, implementation, log_item, mark_pattern=None):
    +    _stylize(str_, implementation, log_item, IMPLEMENTATION, mark_pattern)
    +
    +
    +def _update_inputs(str_, inputs, log_item, mark_pattern=None):
    +    _stylize(str_, inputs, log_item, INPUTS, mark_pattern)
    +
    +
    +def _update_timestamp(str_, timestamp, log_item):
    +    _stylize(str_, timestamp, log_item, TIMESTAMP)
    +
    +
    +def _update_message(str_, message, log_item, mark_pattern=None):
    +    _stylize(str_, message, log_item, MESSAGE, mark_pattern)
    +
    +
    +def _update_level(str_, log_item):
    +    _stylize(str_, log_item.level[0], log_item, LEVEL)
    +
    +
    +def _stylize(stylized_str, msg, log_item, msg_type, mark_pattern=None):
    +    matched_str = _find_pattern(_PATTERNS[FIELD_TYPE][msg_type], stylized_str._str)
    +    if not matched_str:
    +        return stylized_str
    +
    +    substring = Color.stylize(matched_str)
    +
    +    substring.format(**{msg_type: msg})
    +    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):
    +    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
    +
    +
    +def _end_execution_schema(log_item):
    +    if log_item.task:
    +        # This can't be an end workflow log
    +        return
    +    for state, pattern in _PATTERNS[FINAL_STATES].items():
    +        if re.match(pattern, log_item.msg):
    +            return _FINAL_STATES[state]
    +
    +
    +def _resolve_schema(msg_type, log_item):
    +    schema = _end_execution_schema(log_item)
    +
    +    if schema is None:
    +        typed_schema_config = _styles(msg_type).get(log_item.level.lower())
    --- End diff --
    
    Add comments for each here


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] incubator-ariatosca pull request #109: ARIA-146-Support-colorful-execution-l...

Posted by mxmrlv <gi...@git.apache.org>.
Github user mxmrlv commented on a diff in the pull request:

    https://github.com/apache/incubator-ariatosca/pull/109#discussion_r113221527
  
    --- Diff: aria/cli/color.py ---
    @@ -0,0 +1,73 @@
    +# Licensed to the Apache Software Foundation (ASF) under one or more
    +# contributor license agreements.  See the NOTICE file distributed with
    +# this work for additional information regarding copyright ownership.
    +# The ASF licenses this file to You under the Apache License, Version 2.0
    +# (the "License"); you may not use this file except in compliance with
    +# the License.  You may obtain a copy of the License at
    +#
    +#     http://www.apache.org/licenses/LICENSE-2.0
    +#
    +# Unless required by applicable law or agreed to in writing, software
    +# distributed under the License is distributed on an "AS IS" BASIS,
    +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    +# See the License for the specific language governing permissions and
    +# limitations under the License.
    +from StringIO import StringIO
    +
    +import colorama
    +
    +colorama.init()
    +
    +
    +def _get_colors(color_type):
    +    for name in dir(color_type):
    +        if not name.startswith('_'):
    +            yield (name.lower(), getattr(color_type, name))
    +
    +
    +class Color(object):
    +    Fore = colorama.Fore
    +    Back = colorama.Back
    +    Style = colorama.Style
    +
    +    _colors = {
    +        'fore': dict(_get_colors(Fore)),
    +        'back': dict(_get_colors(Back)),
    +        'style': dict(_get_colors(Style))
    +    }
    +
    +    class Schema(object):
    +        def __init__(self, **kwargs):
    +            """
    +            It is possible to provide fore, back and style arguments. each could be either
    +            the color is lower case letter, or the actual color from colorama.
    +
    +            """
    +            assert all(arg in Color._colors for arg in kwargs)
    +            self._kwargs = kwargs
    +            self._str = StringIO()
    +            for type_, colors in Color._colors.items():
    +                value = kwargs.pop(type_, None)
    +                # the former case is if the value is a string, the latter is in case of an object.
    +                self._str.write(colors.get(value) or value)
    +
    +        def __str__(self):
    +            return self._str.getvalue()
    +
    +        def __add__(self, other):
    +            return str(self) + str(other)
    +
    +        def __radd__(self, other):
    +            return str(other) + str(self)
    +
    +    @classmethod
    +    def stylize(cls, str_to_stylize, schema):
    +        return schema + str(str_to_stylize) + cls.Style.RESET_ALL
    --- End diff --
    
    format 


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] incubator-ariatosca pull request #109: ARIA-146-Support-colorful-execution-l...

Posted by mxmrlv <gi...@git.apache.org>.
Github user mxmrlv commented on a diff in the pull request:

    https://github.com/apache/incubator-ariatosca/pull/109#discussion_r113236779
  
    --- Diff: aria/cli/color.py ---
    @@ -0,0 +1,73 @@
    +# Licensed to the Apache Software Foundation (ASF) under one or more
    +# contributor license agreements.  See the NOTICE file distributed with
    +# this work for additional information regarding copyright ownership.
    +# The ASF licenses this file to You under the Apache License, Version 2.0
    +# (the "License"); you may not use this file except in compliance with
    +# the License.  You may obtain a copy of the License at
    +#
    +#     http://www.apache.org/licenses/LICENSE-2.0
    +#
    +# Unless required by applicable law or agreed to in writing, software
    +# distributed under the License is distributed on an "AS IS" BASIS,
    +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    +# See the License for the specific language governing permissions and
    +# limitations under the License.
    +from StringIO import StringIO
    +
    +import colorama
    +
    +colorama.init()
    +
    +
    +def _get_colors(color_type):
    +    for name in dir(color_type):
    +        if not name.startswith('_'):
    +            yield (name.lower(), getattr(color_type, name))
    +
    +
    +class Color(object):
    +    Fore = colorama.Fore
    +    Back = colorama.Back
    +    Style = colorama.Style
    +
    +    _colors = {
    +        'fore': dict(_get_colors(Fore)),
    +        'back': dict(_get_colors(Back)),
    +        'style': dict(_get_colors(Style))
    +    }
    +
    +    class Schema(object):
    +        def __init__(self, **kwargs):
    +            """
    +            It is possible to provide fore, back and style arguments. each could be either
    +            the color is lower case letter, or the actual color from colorama.
    +
    +            """
    +            assert all(arg in Color._colors for arg in kwargs)
    +            self._kwargs = kwargs
    +            self._str = StringIO()
    +            for type_, colors in Color._colors.items():
    +                value = kwargs.pop(type_, None)
    +                # the former case is if the value is a string, the latter is in case of an object.
    +                self._str.write(colors.get(value) or value)
    +
    +        def __str__(self):
    +            return self._str.getvalue()
    +
    +        def __add__(self, other):
    +            return str(self) + str(other)
    +
    +        def __radd__(self, other):
    +            return str(other) + str(self)
    +
    +    @classmethod
    +    def stylize(cls, str_to_stylize, schema):
    +        return schema + str(str_to_stylize) + cls.Style.RESET_ALL
    +
    +    @classmethod
    +    def markup(cls, str_to_stylize, matches, schema):
    +        modified_str = str_to_stylize
    +        for group_index in xrange(len(matches.regs)):
    --- End diff --
    
    move regex stuff here


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] incubator-ariatosca pull request #109: ARIA-146-Support-colorful-execution-l...

Posted by mxmrlv <gi...@git.apache.org>.
Github user mxmrlv commented on a diff in the pull request:

    https://github.com/apache/incubator-ariatosca/pull/109#discussion_r113236075
  
    --- Diff: aria/cli/color.py ---
    @@ -0,0 +1,73 @@
    +# Licensed to the Apache Software Foundation (ASF) under one or more
    +# contributor license agreements.  See the NOTICE file distributed with
    +# this work for additional information regarding copyright ownership.
    +# The ASF licenses this file to You under the Apache License, Version 2.0
    +# (the "License"); you may not use this file except in compliance with
    +# the License.  You may obtain a copy of the License at
    +#
    +#     http://www.apache.org/licenses/LICENSE-2.0
    +#
    +# Unless required by applicable law or agreed to in writing, software
    +# distributed under the License is distributed on an "AS IS" BASIS,
    +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    +# See the License for the specific language governing permissions and
    +# limitations under the License.
    +from StringIO import StringIO
    +
    +import colorama
    +
    +colorama.init()
    +
    +
    +def _get_colors(color_type):
    --- End diff --
    
    put on bottom of the class


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] incubator-ariatosca pull request #109: ARIA-146-Support-colorful-execution-l...

Posted by mxmrlv <gi...@git.apache.org>.
Github user mxmrlv commented on a diff in the pull request:

    https://github.com/apache/incubator-ariatosca/pull/109#discussion_r113656605
  
    --- Diff: aria/cli/execution_logging.py ---
    @@ -12,67 +12,228 @@
     # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     # See the License for the specific language governing permissions and
     # limitations under the License.
    -
    +import os
    +import re
     from StringIO import StringIO
     
     from . import logger
    +from .color import Color
     from .env import env
     
    -DEFAULT_FORMATTING = {
    -    logger.NO_VERBOSE: {'message': '{item.msg}'},
    -    logger.LOW_VERBOSE: {
    -        'message': '{timestamp} | {item.level[0]} | {item.msg}',
    -        'timestamp': '%H:%M:%S'
    +
    +FIELD_TYPE = 'field_type'
    +LEVEL = 'level'
    +TIMESTAMP = 'timestamp'
    +MESSAGE = 'message'
    +IMPLEMENTATION = 'implementation'
    +INPUTS = 'inputs'
    +TRACEBACK = 'traceback'
    +MARKER = 'marker'
    +
    +FINAL_STATES = 'final_states'
    +SUCCESS_STATE = 'success'
    +CANCEL_STATE = 'cancel'
    +FAIL_STATE = 'fail'
    +
    +_EXECUTION_BASE_PATTERN = "\'.*\' workflow execution "
    +_SUCCESSFUL_EXECUTION_PATTERN = _EXECUTION_BASE_PATTERN + "succeeded"
    +_FAILED_EXECUTION_PATTERN = _EXECUTION_BASE_PATTERN + "failed"
    +_CANCELED_EXECUTION_PATTERN = _EXECUTION_BASE_PATTERN + "canceled"
    +
    +_TIMESTAMP_PATTERN = '.*({timestamp.*?}).*'
    +_LEVEL_PATTERN = '.*({level.*?}).*'
    +_MESSAGE_PATTERN = '.*({message.*?}).*'
    +_IMPLEMENTATION_PATTERN = '.*({implementation.*?}).*'
    +_INPUTS_PATTERN = '.*({inputs.*?}).*'
    +
    +_PATTERNS = {
    +    FINAL_STATES: {
    +        SUCCESS_STATE: re.compile(_SUCCESSFUL_EXECUTION_PATTERN),
    +        CANCEL_STATE: re.compile(_CANCELED_EXECUTION_PATTERN),
    +        FAIL_STATE: re.compile(_FAILED_EXECUTION_PATTERN),
         },
    -    logger.MEDIUM_VERBOSE: {
    -        'message': '{timestamp} | {item.level[0]} | {implementation} | {item.msg} ',
    -        'timestamp': '%H:%M:%S'
    +    FIELD_TYPE: {
    +        IMPLEMENTATION: re.compile(_IMPLEMENTATION_PATTERN),
    +        LEVEL: re.compile(_LEVEL_PATTERN),
    +        MESSAGE: re.compile(_MESSAGE_PATTERN),
    +        INPUTS: re.compile(_INPUTS_PATTERN),
    +        TIMESTAMP: re.compile(_TIMESTAMP_PATTERN)
    +    }
    +}
    +
    +_FINAL_STATES = {
    +    SUCCESS_STATE: Color.Fore.GREEN,
    +    CANCEL_STATE: Color.Fore.YELLOW,
    +    FAIL_STATE: Color.Fore.RED
    +}
    +
    +_DEFAULT_STYLE = {
    +    LEVEL: {
    +        'info': {'fore': 'lightmagenta_ex'},
    +        'debug': {'fore': 'lightmagenta_ex', 'style': 'dim'},
    +        'error': {'fore': 'red', 'style': 'bright'},
         },
    -    logger.HIGH_VERBOSE: {
    -        'message': '{timestamp} | {item.level[0]} | {implementation}({inputs}) | {item.msg} ',
    -        'timestamp': '%H:%M:%S'
    +    TIMESTAMP: {
    +        'info': {'fore': 'lightmagenta_ex'},
    +        'debug': {'fore': 'lightmagenta_ex', 'style': 'dim'},
    +        'error': {'fore': 'red', 'style': 'bright'},
         },
    -}
    +    MESSAGE: {
    +        'info': {'fore': 'lightblue_ex'},
    +        'debug': {'fore': 'lightblue_ex', 'style': 'dim'},
    +        'error': {'fore': 'red', 'style': 'bright'},
    +    },
    +    IMPLEMENTATION:{
    +        'info': {'fore': 'lightblack_ex'},
    +        'debug': {'fore': 'lightblack_ex', 'style': 'dim'},
    +        'error': {'fore': 'red', 'style': 'bright'},
    +    },
    +    INPUTS: {
    +        'info': {'fore': 'blue'},
    +        'debug': {'fore': 'blue', 'style': 'dim'},
    +        'error': {'fore': 'red', 'style': 'bright'},
    +    },
    +    TRACEBACK: {'error': {'fore': 'red'}},
     
    +    MARKER: 'lightyellow_ex'
    +}
     
    -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)
    +def stylize_log(item, mark_pattern):
     
    +    # implementation
         if item.task:
    -        formatting_kwargs['implementation'] = item.task.implementation
    -        formatting_kwargs['inputs'] = dict(i.unwrap() for i in item.task.inputs.values())
    +        # operation task
    +        implementation = item.task.implementation
    +        inputs = dict(i.unwrap() for i in item.task.inputs.values())
         else:
    -        formatting_kwargs['implementation'] = item.execution.workflow_name
    -        formatting_kwargs['inputs'] = dict(i.unwrap() for i in item.execution.inputs.values())
    +        # execution task
    +        implementation = item.execution.workflow_name
    +        inputs = dict(i.unwrap() for i in item.execution.inputs.values())
     
    -    if 'timestamp' in formatting:
    -        formatting_kwargs['timestamp'] = item.created_at.strftime(formatting['timestamp'])
    -    else:
    -        formatting_kwargs['timestamp'] = item.created_at
    -
    -    msg.write(formatting['message'].format(**formatting_kwargs))
    +    # TODO: use the is_workflow_log
    +    stylized_str = Color.stylize(_get_format())
    +    _update_level(stylized_str, item)
    --- End diff --
    
    populate


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] incubator-ariatosca pull request #109: ARIA-146-Support-colorful-execution-l...

Posted by mxmrlv <gi...@git.apache.org>.
Github user mxmrlv commented on a diff in the pull request:

    https://github.com/apache/incubator-ariatosca/pull/109#discussion_r113652780
  
    --- Diff: aria/cli/config/config.py ---
    @@ -71,3 +71,15 @@ def filename(self):
             @property
             def loggers(self):
                 return self._logging.get('loggers', {})
    +
    +        @property
    --- End diff --
    
    maybe add class


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] incubator-ariatosca pull request #109: ARIA-146-Support-colorful-execution-l...

Posted by mxmrlv <gi...@git.apache.org>.
Github user mxmrlv commented on a diff in the pull request:

    https://github.com/apache/incubator-ariatosca/pull/109#discussion_r113656083
  
    --- Diff: aria/cli/execution_logging.py ---
    @@ -12,67 +12,228 @@
     # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     # See the License for the specific language governing permissions and
     # limitations under the License.
    -
    +import os
    +import re
     from StringIO import StringIO
     
     from . import logger
    +from .color import Color
     from .env import env
     
    -DEFAULT_FORMATTING = {
    -    logger.NO_VERBOSE: {'message': '{item.msg}'},
    -    logger.LOW_VERBOSE: {
    -        'message': '{timestamp} | {item.level[0]} | {item.msg}',
    -        'timestamp': '%H:%M:%S'
    +
    +FIELD_TYPE = 'field_type'
    +LEVEL = 'level'
    +TIMESTAMP = 'timestamp'
    +MESSAGE = 'message'
    +IMPLEMENTATION = 'implementation'
    +INPUTS = 'inputs'
    +TRACEBACK = 'traceback'
    +MARKER = 'marker'
    +
    +FINAL_STATES = 'final_states'
    +SUCCESS_STATE = 'success'
    +CANCEL_STATE = 'cancel'
    +FAIL_STATE = 'fail'
    +
    +_EXECUTION_BASE_PATTERN = "\'.*\' workflow execution "
    +_SUCCESSFUL_EXECUTION_PATTERN = _EXECUTION_BASE_PATTERN + "succeeded"
    +_FAILED_EXECUTION_PATTERN = _EXECUTION_BASE_PATTERN + "failed"
    +_CANCELED_EXECUTION_PATTERN = _EXECUTION_BASE_PATTERN + "canceled"
    +
    +_TIMESTAMP_PATTERN = '.*({timestamp.*?}).*'
    --- End diff --
    
    add consts


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] incubator-ariatosca pull request #109: ARIA-146-Support-colorful-execution-l...

Posted by mxmrlv <gi...@git.apache.org>.
Github user mxmrlv commented on a diff in the pull request:

    https://github.com/apache/incubator-ariatosca/pull/109#discussion_r113227509
  
    --- Diff: aria/cli/execution_logging.py ---
    @@ -12,62 +12,208 @@
     # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     # See the License for the specific language governing permissions and
     # limitations under the License.
    -
    +import os
    +import re
     from StringIO import StringIO
    +from contextlib import contextmanager
     
     from . import logger
    +from .color import Color
     from .env import env
     
    +
    +LEVEL = 'level'
    +TIMESTAMP = 'timestamp'
    +MESSAGE = 'message'
    +IMPLEMENTATION = 'implementation'
    +INPUTS = 'inputs'
    +TRACEBACK = 'traceback'
    +MARKER = 'marker'
    +
    +FINAL_STATES = 'final_states'
    +SUCCESS_STATE = 'success'
    +CANCEL_STATE = 'cancel'
    +FAIL_STATE = 'fail'
    +
    +
    +_EXECUTION_BASE_PATTERN = "\'.*\' workflow execution "
    +_SUCCESSFUL_EXECUTION_PATTERN = _EXECUTION_BASE_PATTERN + "succeeded"
    +_FAILED_EXECUTION_PATTERN = _EXECUTION_BASE_PATTERN + "failed"
    +_CANCELED_EXECUTION_PATTERN = _EXECUTION_BASE_PATTERN + "canceled"
    +
     DEFAULT_FORMATTING = {
    -    logger.NO_VERBOSE: {'message': '{item.msg}'},
    +    logger.NO_VERBOSE: {'message': '{message}'},
         logger.LOW_VERBOSE: {
    -        'message': '{timestamp} | {item.level[0]} | {item.msg}',
    -        'timestamp': '%H:%M:%S'
    +        MESSAGE: '{timestamp} | {level} | {message}',
    +        LEVEL: '{level[0]}',
    +        TIMESTAMP: '%H:%M:%S',
         },
         logger.MEDIUM_VERBOSE: {
    -        'message': '{timestamp} | {item.level[0]} | {implementation} | {item.msg} ',
    -        'timestamp': '%H:%M:%S'
    +        MESSAGE: '{timestamp} | {level} | {implementation} | {message} ',
    +        LEVEL: '{level[0]}',
    +        TIMESTAMP: '%H:%M:%S'
         },
         logger.HIGH_VERBOSE: {
    -        'message': '{timestamp} | {item.level[0]} | {implementation}({inputs}) | {item.msg} ',
    -        'timestamp': '%H:%M:%S'
    +        MESSAGE: '{timestamp} | {level} | {implementation} | {inputs} | {message} ',
    +        LEVEL: '{level[0]}',
    +        TIMESTAMP: '%H:%M:%S'
    +    },
    +}
    +
    +DEFAULT_STYLING = {
    +    LEVEL: {
    +        'info': Color.Fore.LIGHTMAGENTA_EX,
    +        'debug': Color.Schema(fore=Color.Fore.LIGHTMAGENTA_EX, style=Color.Style.DIM),
    +        'error': Color.Schema(fore=Color.Fore.RED, style=Color.Style.BRIGHT),
         },
    +    TIMESTAMP: {
    +        'info': Color.Fore.LIGHTMAGENTA_EX,
    +        'debug': Color.Schema(fore=Color.Fore.LIGHTMAGENTA_EX, style=Color.Style.DIM),
    +        'error': Color.Schema(fore=Color.Fore.RED, style=Color.Style.BRIGHT),
    +    },
    +    MESSAGE: {
    +        'info': Color.Fore.LIGHTBLUE_EX,
    +        'debug': Color.Schema(fore=Color.Fore.LIGHTBLUE_EX, style=Color.Style.DIM),
    +        'error': Color.Schema(fore=Color.Fore.RED, style=Color.Style.BRIGHT),
    +    },
    +    IMPLEMENTATION: {
    +        'info': Color.Fore.LIGHTBLACK_EX,
    +        'debug': Color.Schema(fore=Color.Fore.LIGHTBLACK_EX, style=Color.Style.DIM),
    +        'error': Color.Schema(fore=Color.Fore.RED, style=Color.Style.BRIGHT),
    +    },
    +    INPUTS: {
    +        'info': Color.Fore.BLUE,
    +        'debug': Color.Schema(fore=Color.Fore.BLUE, style=Color.Style.DIM),
    +        'error': Color.Schema(fore=Color.Fore.RED, style=Color.Style.BRIGHT),
    +    },
    +    TRACEBACK: {'error': Color.Fore.RED},
    +
    +    MARKER: Color.Back.LIGHTYELLOW_EX,
    +    FINAL_STATES: {
    --- End diff --
    
    extract somehow so this isnt configurable


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] incubator-ariatosca pull request #109: ARIA-146-Support-colorful-execution-l...

Posted by mxmrlv <gi...@git.apache.org>.
Github user mxmrlv commented on a diff in the pull request:

    https://github.com/apache/incubator-ariatosca/pull/109#discussion_r113658733
  
    --- Diff: aria/cli/execution_logging.py ---
    @@ -12,67 +12,228 @@
     # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     # See the License for the specific language governing permissions and
     # limitations under the License.
    -
    +import os
    +import re
     from StringIO import StringIO
     
     from . import logger
    +from .color import Color
     from .env import env
     
    -DEFAULT_FORMATTING = {
    -    logger.NO_VERBOSE: {'message': '{item.msg}'},
    -    logger.LOW_VERBOSE: {
    -        'message': '{timestamp} | {item.level[0]} | {item.msg}',
    -        'timestamp': '%H:%M:%S'
    +
    +FIELD_TYPE = 'field_type'
    +LEVEL = 'level'
    +TIMESTAMP = 'timestamp'
    +MESSAGE = 'message'
    +IMPLEMENTATION = 'implementation'
    +INPUTS = 'inputs'
    +TRACEBACK = 'traceback'
    +MARKER = 'marker'
    +
    +FINAL_STATES = 'final_states'
    +SUCCESS_STATE = 'success'
    +CANCEL_STATE = 'cancel'
    +FAIL_STATE = 'fail'
    +
    +_EXECUTION_BASE_PATTERN = "\'.*\' workflow execution "
    +_SUCCESSFUL_EXECUTION_PATTERN = _EXECUTION_BASE_PATTERN + "succeeded"
    +_FAILED_EXECUTION_PATTERN = _EXECUTION_BASE_PATTERN + "failed"
    +_CANCELED_EXECUTION_PATTERN = _EXECUTION_BASE_PATTERN + "canceled"
    +
    +_TIMESTAMP_PATTERN = '.*({timestamp.*?}).*'
    +_LEVEL_PATTERN = '.*({level.*?}).*'
    +_MESSAGE_PATTERN = '.*({message.*?}).*'
    +_IMPLEMENTATION_PATTERN = '.*({implementation.*?}).*'
    +_INPUTS_PATTERN = '.*({inputs.*?}).*'
    +
    +_PATTERNS = {
    +    FINAL_STATES: {
    +        SUCCESS_STATE: re.compile(_SUCCESSFUL_EXECUTION_PATTERN),
    +        CANCEL_STATE: re.compile(_CANCELED_EXECUTION_PATTERN),
    +        FAIL_STATE: re.compile(_FAILED_EXECUTION_PATTERN),
         },
    -    logger.MEDIUM_VERBOSE: {
    -        'message': '{timestamp} | {item.level[0]} | {implementation} | {item.msg} ',
    -        'timestamp': '%H:%M:%S'
    +    FIELD_TYPE: {
    +        IMPLEMENTATION: re.compile(_IMPLEMENTATION_PATTERN),
    +        LEVEL: re.compile(_LEVEL_PATTERN),
    +        MESSAGE: re.compile(_MESSAGE_PATTERN),
    +        INPUTS: re.compile(_INPUTS_PATTERN),
    +        TIMESTAMP: re.compile(_TIMESTAMP_PATTERN)
    +    }
    +}
    +
    +_FINAL_STATES = {
    +    SUCCESS_STATE: Color.Fore.GREEN,
    +    CANCEL_STATE: Color.Fore.YELLOW,
    +    FAIL_STATE: Color.Fore.RED
    +}
    +
    +_DEFAULT_STYLE = {
    +    LEVEL: {
    +        'info': {'fore': 'lightmagenta_ex'},
    +        'debug': {'fore': 'lightmagenta_ex', 'style': 'dim'},
    +        'error': {'fore': 'red', 'style': 'bright'},
         },
    -    logger.HIGH_VERBOSE: {
    -        'message': '{timestamp} | {item.level[0]} | {implementation}({inputs}) | {item.msg} ',
    -        'timestamp': '%H:%M:%S'
    +    TIMESTAMP: {
    +        'info': {'fore': 'lightmagenta_ex'},
    +        'debug': {'fore': 'lightmagenta_ex', 'style': 'dim'},
    +        'error': {'fore': 'red', 'style': 'bright'},
         },
    -}
    +    MESSAGE: {
    +        'info': {'fore': 'lightblue_ex'},
    +        'debug': {'fore': 'lightblue_ex', 'style': 'dim'},
    +        'error': {'fore': 'red', 'style': 'bright'},
    +    },
    +    IMPLEMENTATION:{
    +        'info': {'fore': 'lightblack_ex'},
    +        'debug': {'fore': 'lightblack_ex', 'style': 'dim'},
    +        'error': {'fore': 'red', 'style': 'bright'},
    +    },
    +    INPUTS: {
    +        'info': {'fore': 'blue'},
    +        'debug': {'fore': 'blue', 'style': 'dim'},
    +        'error': {'fore': 'red', 'style': 'bright'},
    +    },
    +    TRACEBACK: {'error': {'fore': 'red'}},
     
    +    MARKER: 'lightyellow_ex'
    +}
     
    -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)
    +def stylize_log(item, mark_pattern):
     
    +    # implementation
         if item.task:
    -        formatting_kwargs['implementation'] = item.task.implementation
    -        formatting_kwargs['inputs'] = dict(i.unwrap() for i in item.task.inputs.values())
    +        # operation task
    +        implementation = item.task.implementation
    +        inputs = dict(i.unwrap() for i in item.task.inputs.values())
         else:
    -        formatting_kwargs['implementation'] = item.execution.workflow_name
    -        formatting_kwargs['inputs'] = dict(i.unwrap() for i in item.execution.inputs.values())
    +        # execution task
    +        implementation = item.execution.workflow_name
    +        inputs = dict(i.unwrap() for i in item.execution.inputs.values())
     
    -    if 'timestamp' in formatting:
    -        formatting_kwargs['timestamp'] = item.created_at.strftime(formatting['timestamp'])
    -    else:
    -        formatting_kwargs['timestamp'] = item.created_at
    -
    -    msg.write(formatting['message'].format(**formatting_kwargs))
    +    # TODO: use the is_workflow_log
    +    stylized_str = Color.stylize(_get_format())
    +    _update_level(stylized_str, item)
    +    _update_timestamp(stylized_str, item.created_at, item)
    +    _update_message(stylized_str, item.msg, item, mark_pattern)
    +    _update_inputs(stylized_str, inputs, item, mark_pattern)
    +    _update_implementation(stylized_str, implementation, item, mark_pattern)
     
    +    msg = StringIO()
    +    msg.write(str(stylized_str))
         # Add the exception and the error msg.
         if item.traceback and env.logging.verbosity_level >= logger.MEDIUM_VERBOSE:
    -        for line in item.traceback.splitlines(True):
    -            msg.write('\t' + '|' + line)
    +        msg.write(os.linesep)
    +        msg.writelines(_get_traceback('\t' + '|' + line, item, mark_pattern)
    +                       for line in item.traceback.splitlines(True))
     
         return msg.getvalue()
     
     
    -def log(item, *args, **kwargs):
    -    return getattr(env.logging.logger, item.level.lower())(_str(item), *args, **kwargs)
    +def log(item, mark_pattern=None, *args, **kwargs):
    +    leveled_log = getattr(env.logging.logger, item.level.lower())
    +    return leveled_log(stylize_log(item, mark_pattern), *args, **kwargs)
     
     
    -def log_list(iterator):
    +def log_list(iterator, mark_pattern=None):
         any_logs = False
         for item in iterator:
    -        log(item)
    +        log(item, mark_pattern)
             any_logs = True
         return any_logs
    +
    +
    +def _find_pattern(pattern, field_value):
    +    # TODO: this finds the matching field type according to a pattern
    --- End diff --
    
    check


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] incubator-ariatosca pull request #109: ARIA-146-Support-colorful-execution-l...

Posted by mxmrlv <gi...@git.apache.org>.
Github user mxmrlv commented on a diff in the pull request:

    https://github.com/apache/incubator-ariatosca/pull/109#discussion_r113227303
  
    --- Diff: aria/cli/execution_logging.py ---
    @@ -12,62 +12,208 @@
     # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     # See the License for the specific language governing permissions and
     # limitations under the License.
    -
    +import os
    +import re
     from StringIO import StringIO
    +from contextlib import contextmanager
     
     from . import logger
    +from .color import Color
     from .env import env
     
    +
    +LEVEL = 'level'
    +TIMESTAMP = 'timestamp'
    +MESSAGE = 'message'
    +IMPLEMENTATION = 'implementation'
    +INPUTS = 'inputs'
    +TRACEBACK = 'traceback'
    +MARKER = 'marker'
    +
    +FINAL_STATES = 'final_states'
    +SUCCESS_STATE = 'success'
    +CANCEL_STATE = 'cancel'
    +FAIL_STATE = 'fail'
    +
    +
    +_EXECUTION_BASE_PATTERN = "\'.*\' workflow execution "
    +_SUCCESSFUL_EXECUTION_PATTERN = _EXECUTION_BASE_PATTERN + "succeeded"
    +_FAILED_EXECUTION_PATTERN = _EXECUTION_BASE_PATTERN + "failed"
    +_CANCELED_EXECUTION_PATTERN = _EXECUTION_BASE_PATTERN + "canceled"
    +
     DEFAULT_FORMATTING = {
    -    logger.NO_VERBOSE: {'message': '{item.msg}'},
    +    logger.NO_VERBOSE: {'message': '{message}'},
         logger.LOW_VERBOSE: {
    -        'message': '{timestamp} | {item.level[0]} | {item.msg}',
    -        'timestamp': '%H:%M:%S'
    +        MESSAGE: '{timestamp} | {level} | {message}',
    +        LEVEL: '{level[0]}',
    +        TIMESTAMP: '%H:%M:%S',
         },
         logger.MEDIUM_VERBOSE: {
    -        'message': '{timestamp} | {item.level[0]} | {implementation} | {item.msg} ',
    -        'timestamp': '%H:%M:%S'
    +        MESSAGE: '{timestamp} | {level} | {implementation} | {message} ',
    +        LEVEL: '{level[0]}',
    +        TIMESTAMP: '%H:%M:%S'
         },
         logger.HIGH_VERBOSE: {
    -        'message': '{timestamp} | {item.level[0]} | {implementation}({inputs}) | {item.msg} ',
    -        'timestamp': '%H:%M:%S'
    +        MESSAGE: '{timestamp} | {level} | {implementation} | {inputs} | {message} ',
    +        LEVEL: '{level[0]}',
    +        TIMESTAMP: '%H:%M:%S'
    +    },
    +}
    +
    +DEFAULT_STYLING = {
    +    LEVEL: {
    +        'info': Color.Fore.LIGHTMAGENTA_EX,
    +        'debug': Color.Schema(fore=Color.Fore.LIGHTMAGENTA_EX, style=Color.Style.DIM),
    +        'error': Color.Schema(fore=Color.Fore.RED, style=Color.Style.BRIGHT),
         },
    +    TIMESTAMP: {
    +        'info': Color.Fore.LIGHTMAGENTA_EX,
    +        'debug': Color.Schema(fore=Color.Fore.LIGHTMAGENTA_EX, style=Color.Style.DIM),
    +        'error': Color.Schema(fore=Color.Fore.RED, style=Color.Style.BRIGHT),
    +    },
    +    MESSAGE: {
    +        'info': Color.Fore.LIGHTBLUE_EX,
    +        'debug': Color.Schema(fore=Color.Fore.LIGHTBLUE_EX, style=Color.Style.DIM),
    +        'error': Color.Schema(fore=Color.Fore.RED, style=Color.Style.BRIGHT),
    +    },
    +    IMPLEMENTATION: {
    +        'info': Color.Fore.LIGHTBLACK_EX,
    +        'debug': Color.Schema(fore=Color.Fore.LIGHTBLACK_EX, style=Color.Style.DIM),
    +        'error': Color.Schema(fore=Color.Fore.RED, style=Color.Style.BRIGHT),
    +    },
    +    INPUTS: {
    +        'info': Color.Fore.BLUE,
    +        'debug': Color.Schema(fore=Color.Fore.BLUE, style=Color.Style.DIM),
    +        'error': Color.Schema(fore=Color.Fore.RED, style=Color.Style.BRIGHT),
    +    },
    +    TRACEBACK: {'error': Color.Fore.RED},
    +
    +    MARKER: Color.Back.LIGHTYELLOW_EX,
    --- End diff --
    
    default


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---