From c95fce1b69ea91c27358753bd68a5f8a8f406aff Mon Sep 17 00:00:00 2001 From: vvzvlad Date: Sun, 19 Jan 2025 11:40:43 +0300 Subject: [PATCH] Add clean_ansi function to checker.py for log processing This update introduces a new `clean_ansi` function to remove ANSI escape sequences from log output, enhancing readability. The `check_logs` function has been modified to utilize this new function, ensuring that the logs retrieved from Docker are plain text, which improves clarity for subsequent log analysis. --- checker.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/checker.py b/checker.py index 9c0c82a..f2fbb4f 100644 --- a/checker.py +++ b/checker.py @@ -130,11 +130,14 @@ class GRIST: return record.Value raise ValueError(f"Setting {key} not found") +def clean_ansi(text): + ansi_escape = re.compile(r'\x1B(?:[@-Z\\-_]|\[[0-?]*[ -/]*[@-~])') + return ansi_escape.sub('', text) def check_logs(log_handler): try: - logs = subprocess.run(['docker', 'logs', '--since', '10m', '--no-color', 'infernet-node'], capture_output=True, text=True, check=True) - log_content = logs.stdout + logs = subprocess.run(['docker', 'logs', '--since', '10m', 'infernet-node'], capture_output=True, text=True, check=True) + log_content = clean_ansi(logs.stdout) except subprocess.CalledProcessError as e: raise RuntimeError(f"Error running docker logs: {e}")