Return-Path: X-Original-To: archive-asf-public-internal@cust-asf2.ponee.io Delivered-To: archive-asf-public-internal@cust-asf2.ponee.io Received: from cust-asf.ponee.io (cust-asf.ponee.io [163.172.22.183]) by cust-asf2.ponee.io (Postfix) with ESMTP id 22803200C5B for ; Thu, 27 Apr 2017 12:48:32 +0200 (CEST) Received: by cust-asf.ponee.io (Postfix) id 21229160BA7; Thu, 27 Apr 2017 10:48:32 +0000 (UTC) Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by cust-asf.ponee.io (Postfix) with SMTP id 45CFB160BBC for ; Thu, 27 Apr 2017 12:48:31 +0200 (CEST) Received: (qmail 85112 invoked by uid 500); 27 Apr 2017 10:48:30 -0000 Mailing-List: contact dev-help@ariatosca.incubator.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@ariatosca.incubator.apache.org Delivered-To: mailing list dev@ariatosca.incubator.apache.org Received: (qmail 85024 invoked by uid 99); 27 Apr 2017 10:48:30 -0000 Received: from pnap-us-west-generic-nat.apache.org (HELO spamd2-us-west.apache.org) (209.188.14.142) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 27 Apr 2017 10:48:30 +0000 Received: from localhost (localhost [127.0.0.1]) by spamd2-us-west.apache.org (ASF Mail Server at spamd2-us-west.apache.org) with ESMTP id D494D1A7A38 for ; Thu, 27 Apr 2017 10:48:29 +0000 (UTC) X-Virus-Scanned: Debian amavisd-new at spamd2-us-west.apache.org X-Spam-Flag: NO X-Spam-Score: -4.02 X-Spam-Level: X-Spam-Status: No, score=-4.02 tagged_above=-999 required=6.31 tests=[KAM_LAZY_DOMAIN_SECURITY=1, RCVD_IN_DNSWL_HI=-5, RCVD_IN_MSPIKE_H3=-0.01, RCVD_IN_MSPIKE_WL=-0.01, RP_MATCHES_RCVD=-0.001, URIBL_BLOCKED=0.001] autolearn=disabled Received: from mx1-lw-us.apache.org ([10.40.0.8]) by localhost (spamd2-us-west.apache.org [10.40.0.9]) (amavisd-new, port 10024) with ESMTP id Aj9wt1wwJg9c for ; Thu, 27 Apr 2017 10:48:28 +0000 (UTC) Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by mx1-lw-us.apache.org (ASF Mail Server at mx1-lw-us.apache.org) with SMTP id 484835FC1C for ; Thu, 27 Apr 2017 10:48:28 +0000 (UTC) Received: (qmail 84726 invoked by uid 99); 27 Apr 2017 10:48:27 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 27 Apr 2017 10:48:27 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id B2784DF989; Thu, 27 Apr 2017 10:48:27 +0000 (UTC) From: mxmrlv To: dev@ariatosca.incubator.apache.org Reply-To: dev@ariatosca.incubator.apache.org References: In-Reply-To: Subject: [GitHub] incubator-ariatosca pull request #109: ARIA-146-Support-colorful-execution-l... Content-Type: text/plain Message-Id: <20170427104827.B2784DF989@git1-us-west.apache.org> Date: Thu, 27 Apr 2017 10:48:27 +0000 (UTC) archived-at: Thu, 27 Apr 2017 10:48:32 -0000 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. ---