Skip to content

Commit

Permalink
fix: strip ansi on file_handler as well
Browse files Browse the repository at this point in the history
  • Loading branch information
iamkenos committed Oct 10, 2024
1 parent 54de043 commit 13e1e62
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 2 deletions.
3 changes: 2 additions & 1 deletion behavex/environment.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
from behavex.conf_mgr import get_env, get_param
from behavex.global_vars import global_vars
from behavex.outputs import report_json, report_xml
from behavex.outputs.report_utils import create_log_path
from behavex.outputs.report_utils import create_log_path, strip_ansi_codes
from behavex.utils import (LOGGING_CFG, create_custom_log_when_called,
get_autoretry_attempts, get_logging_level,
get_scenario_tags, get_scenarios_instances)
Expand Down Expand Up @@ -197,6 +197,7 @@ def _add_log_handler(log_path):
)
log_level = get_logging_level()
logging.getLogger().setLevel(log_level)
file_handler.addFilter(lambda record: setattr(record, 'msg', strip_ansi_codes(str(record.msg))) or True)
file_handler.setFormatter(_get_log_formatter())
logging.getLogger().addHandler(file_handler)
return file_handler
Expand Down
4 changes: 3 additions & 1 deletion behavex/outputs/report_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,6 @@ def gather_steps(features):


def gather_errors(scenario, retrieve_step_name=False):
strip_ansi_codes = lambda text: re.sub(r'\x1B\[[0-?9;]*[mGJK]', '', text)
error_msg = list(map(lambda line: strip_ansi_codes(line), scenario['error_msg']))
if retrieve_step_name:
return error_msg, scenario['error_lines'], scenario['error_step']
Expand Down Expand Up @@ -451,3 +450,6 @@ def get_environment_details():
environment_details_raw_data = os.getenv('ENVIRONMENT_DETAILS', None)
environment_details = environment_details_raw_data.split(',') if environment_details_raw_data else []
return environment_details

def strip_ansi_codes(from_str: str):
return re.sub(r'\x1B\[[0-?9;]*[mGJK]', '', from_str)

0 comments on commit 13e1e62

Please sign in to comment.