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:
parent
cd119be631
commit
c95fce1b69
@ -130,11 +130,14 @@ class GRIST:
|
|||||||
return record.Value
|
return record.Value
|
||||||
raise ValueError(f"Setting {key} not found")
|
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):
|
def check_logs(log_handler):
|
||||||
try:
|
try:
|
||||||
logs = subprocess.run(['docker', 'logs', '--since', '10m', '--no-color', 'infernet-node'], capture_output=True, text=True, check=True)
|
logs = subprocess.run(['docker', 'logs', '--since', '10m', 'infernet-node'], capture_output=True, text=True, check=True)
|
||||||
log_content = logs.stdout
|
log_content = clean_ansi(logs.stdout)
|
||||||
except subprocess.CalledProcessError as e:
|
except subprocess.CalledProcessError as e:
|
||||||
raise RuntimeError(f"Error running docker logs: {e}")
|
raise RuntimeError(f"Error running docker logs: {e}")
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user