Update: Major code refactor
CI/CD Pipeline / Unit Tests (Python 3.12) (push) Successful in 30s
CI/CD Pipeline / Unit Tests (Python 3.13) (push) Successful in 35s
CI/CD Pipeline / Code Quality & Linting (push) Successful in 27s
CI/CD Pipeline / Security Scanning (push) Successful in 2m23s
CI/CD Pipeline / Unit Tests (Python 3.11) (push) Successful in 24s
CI/CD Pipeline / Integration Tests (push) Successful in 26s
CI/CD Pipeline / Generate Test Report (push) Successful in 9s
CI/CD Pipeline / Build Docker Image (push) Successful in 41s
CI/CD Pipeline / CI/CD Pipeline Status (push) Successful in 2s

This commit is contained in:
k.eaven committed 2026-10-24 10:53:09 +00:00
1 parent d891b21ffd
commit 3e03939fd0
13 files changed
+3266 -443

No files matched your search

+66
View File
@@ -0,0 +1,66 @@
"""
Logging Configuration Module
Sets up application-wide logging with:
- Rotating file handler (5MB max, 3 backups) at DEBUG level
- Console handler at INFO level
- Consistent formatting for both handlers
"""
import logging
import os
from logging.handlers import RotatingFileHandler
from pathlib import Path
def setup_logging(log_dir: str = "logs", log_file: str = "pterodisbot.log") -> logging.Logger:
"""
Configure application-wide logging.
Args:
log_dir: Directory for log files (relative to this file)
log_file: Name of the log file
Returns:
Configured logger instance
"""
# Create logs directory if it doesn't exist
logs_path = Path(__file__).parent / log_dir
logs_path.mkdir(parents=True, exist_ok=True)
# Get or create the application logger
logger = logging.getLogger("pterodisbot")
logger.setLevel(logging.DEBUG)
# Avoid adding duplicate handlers if called multiple times
if logger.handlers:
return logger
# File handler for logs (rotates when reaching 5MB, keeps 3 backups)
file_handler = RotatingFileHandler(
filename=logs_path / log_file,
maxBytes=5 * 1024 * 1024, # 5 MiB max log file size
backupCount=3, # Rotate through 3 files
encoding="utf-8",
)
file_handler.setLevel(logging.DEBUG)
file_handler.setFormatter(
logging.Formatter("%(asctime)s - %(levelname)s - %(message)s")
)
logger.addHandler(file_handler)
# Console handler for real-time output (INFO level and above)
console_handler = logging.StreamHandler()
console_handler.setLevel(logging.INFO)
console_handler.setFormatter(
logging.Formatter("%(asctime)s - %(levelname)s - %(message)s")
)
logger.addHandler(console_handler)
logger.info("Initialized logging system with file and console output")
return logger
def get_logger() -> logging.Logger:
"""Get the configured logger instance."""
return logging.getLogger("pterodisbot")