# modules/status_logger.py import logging import os from datetime import datetime STATUS_LOG_FILE = "server_status_log.csv" # Set up logging logging.basicConfig(level=logging.INFO, format='%(asctime)s - %(levelname)s - %(message)s') def log_server_status(server_key, status): timestamp = datetime.now().isoformat() status_str = "UP" if status else "DOWN" # Log to console logging.info(f"Server {server_key} is {status_str}") # Log to file try: file_exists = os.path.exists(STATUS_LOG_FILE) with open(STATUS_LOG_FILE, 'a') as f: if not file_exists: f.write("timestamp,server,status\n") f.write(f"{timestamp},{server_key},{status_str}\n") except Exception as e: logging.error(f"Failed to log server status: {e}") def log_analysis_result(query, success, message=""): timestamp = datetime.now().isoformat() result_str = "SUCCESS" if success else "FAILED" # Log to console logging.info(f"Analysis for '{query}' {result_str}: {message}") # Log to file try: ANALYSIS_LOG_FILE = "analysis_log.csv" file_exists = os.path.exists(ANALYSIS_LOG_FILE) with open(ANALYSIS_LOG_FILE, 'a') as f: if not file_exists: f.write("timestamp,query,result,message\n") f.write(f"{timestamp},\"{query}\",{result_str},\"{message}\"\n") except Exception as e: logging.error(f"Failed to log analysis result: {e}")