20 lines
659 B
Python
20 lines
659 B
Python
import os
|
|
import re
|
|
|
|
LOG_DIR = "log" # Modifica se la tua cartella è altrove
|
|
|
|
def find_logs(log_dir):
|
|
for root, _, files in os.walk(log_dir):
|
|
for fname in files:
|
|
if fname.endswith(".log") or fname.endswith(".jsonlog"):
|
|
yield os.path.join(root, fname)
|
|
|
|
def estrai_errori_da_file(filepath):
|
|
with open(filepath, encoding="utf-8", errors="ignore") as f:
|
|
for n, line in enumerate(f, 1):
|
|
if re.search(r'error', line, re.IGNORECASE):
|
|
print(f"{filepath}:{n}\n{line.strip()}\n")
|
|
|
|
if __name__ == "__main__":
|
|
for filepath in find_logs(LOG_DIR):
|
|
estrai_errori_da_file(filepath) |