add multi file logs filter errors
This commit is contained in:
@@ -7,6 +7,20 @@ cfg = setting.Config()
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
async def send_error_email(unit_name: str, tool_name: str, matlab_cmd: str, matlab_error: str, errors: list, warnings: list) -> None:
|
||||
"""
|
||||
Sends an error email containing details about a MATLAB processing failure.
|
||||
|
||||
The email includes information about the unit, tool, MATLAB command, error message,
|
||||
and lists of specific errors and warnings encountered.
|
||||
|
||||
Args:
|
||||
unit_name (str): The name of the unit involved in the processing.
|
||||
tool_name (str): The name of the tool involved in the processing.
|
||||
matlab_cmd (str): The MATLAB command that was executed.
|
||||
matlab_error (str): The main MATLAB error message.
|
||||
errors (list): A list of detailed error messages from MATLAB.
|
||||
warnings (list): A list of detailed warning messages from MATLAB.
|
||||
"""
|
||||
|
||||
# Creazione dell'oggetto messaggio
|
||||
msg = EmailMessage()
|
||||
|
||||
@@ -1,7 +1,60 @@
|
||||
import glob
|
||||
import os
|
||||
|
||||
import logging
|
||||
|
||||
logger = logging.getLogger()
|
||||
|
||||
def alterna_valori(val1: str, val2: str) -> any:
|
||||
"""
|
||||
Restituisce alternativamente il primo ed il secondo valore
|
||||
"""
|
||||
while True:
|
||||
yield val1
|
||||
yield val2
|
||||
yield val2
|
||||
|
||||
|
||||
async def read_error_lines_from_logs(base_path: str, pattern: str) -> tuple[list[str], list[str]]:
|
||||
"""
|
||||
Reads error and warning lines from log files matching a given pattern within a base path.
|
||||
|
||||
This asynchronous function searches for log files, reads their content, and categorizes
|
||||
lines starting with 'Error' as errors and all other non-empty lines as warnings.
|
||||
|
||||
Args:
|
||||
base_path (str): The base directory where log files are located.
|
||||
pattern (str): The glob-style pattern to match log filenames (e.g., "*.txt", "prefix_*_output_error.txt").
|
||||
|
||||
Returns:
|
||||
tuple[list[str], list[str]]: A tuple containing two lists:
|
||||
- The first list contains all extracted error messages.
|
||||
- The second list contains all extracted warning messages."""
|
||||
# Costruisce il path completo con il pattern
|
||||
search_pattern = os.path.join(base_path, pattern)
|
||||
|
||||
# Trova tutti i file che corrispondono al pattern
|
||||
matching_files = glob.glob(search_pattern)
|
||||
|
||||
if not matching_files:
|
||||
logger.warning(f"Nessun file trovato per il pattern: {search_pattern}")
|
||||
return [], []
|
||||
|
||||
errors = []
|
||||
warnings = []
|
||||
|
||||
for file_path in matching_files:
|
||||
try:
|
||||
with open(file_path, 'r', encoding='utf-8') as file:
|
||||
lines = file.readlines()
|
||||
for line in lines:
|
||||
stripped_line = line.strip()
|
||||
if stripped_line: # Ignora righe vuote
|
||||
if stripped_line.startswith('Error'):
|
||||
errors.append(stripped_line)
|
||||
else:
|
||||
warnings.append(stripped_line)
|
||||
|
||||
except Exception as e:
|
||||
logger.error(f"Errore durante la lettura del file {file_path}: {e}")
|
||||
|
||||
return errors, warnings
|
||||
|
||||
Reference in New Issue
Block a user