[ 
https://issues.apache.org/jira/browse/ARIA-146?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15986346#comment-15986346
 ] 

ASF GitHub Bot commented on ARIA-146:
-------------------------------------

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


> Support colorful execution logging
> ----------------------------------
>
>                 Key: ARIA-146
>                 URL: https://issues.apache.org/jira/browse/ARIA-146
>             Project: AriaTosca
>          Issue Type: Story
>            Reporter: Ran Ziv
>            Assignee: Maxim Orlov
>            Priority: Minor
>
> Add support for printing execution logs in color



--
This message was sent by Atlassian JIRA
(v6.3.15#6346)

Reply via email to