| """ | |
| Logging configuration for Anomaly Detection pipeline. | |
| Creates timestamped log files in the logs directory. | |
| """ | |
| import logging | |
| import os | |
| from datetime import datetime | |
| LOG_FILE = f"{datetime.now().strftime('%m_%d_%Y_%H_%M_%S')}.log" | |
| logs_path = os.path.join(os.getcwd(), "logs", LOG_FILE) | |
| os.makedirs(logs_path, exist_ok=True) | |
| LOG_FILE_PATH = os.path.join(logs_path, LOG_FILE) | |
| logging.basicConfig( | |
| filename=LOG_FILE_PATH, | |
| format="[ %(asctime)s ] %(lineno)d %(name)s - %(levelname)s - %(message)s", | |
| level=logging.INFO | |
| ) | |
| # Also add console handler for visibility | |
| console_handler = logging.StreamHandler() | |
| console_handler.setLevel(logging.INFO) | |
| console_handler.setFormatter(logging.Formatter( | |
| "%(asctime)s - %(name)s - %(levelname)s - %(message)s" | |
| )) | |
| # Get root logger and add console handler | |
| root_logger = logging.getLogger() | |
| root_logger.addHandler(console_handler) | |