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.
This commit is contained in:
@ -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}")
|
||||
|
||||
|
Reference in New Issue
Block a user