Bugfix, plus some QoL upgrades from the Async branch

This commit is contained in:
2025-10-20 14:25:03 -04:00
parent aa8380ac0a
commit f1f33948e3
7 changed files with 299 additions and 218 deletions
+14 -6
View File
@@ -39,22 +39,31 @@ def get_base_directory() -> Path:
def configure_logging(log_dir: Path, log_level: str = "DEBUG"):
log_file = log_dir / "airlocktools.log"
logger = logging.getLogger()
logger.setLevel(getattr(logging, log_level.upper(), logging.DEBUG))
# 🔧 Clear existing handlers
# Always allow all messages to propagate to handlers
logger.setLevel(logging.DEBUG)
# Remove existing handlers
for handler in logger.handlers[:]:
logger.removeHandler(handler)
# File handler always logs DEBUG and above
file_handler = logging.handlers.RotatingFileHandler(
log_file, maxBytes=5_000_000, backupCount=5, encoding='utf-8'
)
file_handler.setFormatter(logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s'))
file_handler.setLevel(logging.DEBUG)
file_handler.setFormatter(logging.Formatter(
'%(asctime)s - %(name)s - %(levelname)s - %(message)s'
))
logger.addHandler(file_handler)
# Console handler respects the configured log level
console_handler = logging.StreamHandler()
console_handler.setLevel(getattr(logging, log_level.upper(), logging.INFO))
console_handler.setFormatter(logging.Formatter('%(levelname)s - %(message)s'))
logger.addHandler(console_handler)
# Optional Windows Event Log handler
if platform.system() == "Windows":
try:
event_handler = logging.handlers.NTEventLogHandler("AirlockTools")
@@ -65,7 +74,7 @@ def configure_logging(log_dir: Path, log_level: str = "DEBUG"):
logger.warning(f"Could not attach Windows Event Log handler: {e}")
logger.debug("✅ Logging configured.")
def get_system_config_path() -> Path:
base_path = Path(getattr(sys, '_MEIPASS', os.path.dirname(os.path.abspath(__file__))))
return base_path.parent / "system_config.json"
@@ -111,7 +120,7 @@ def write_config_to_env(config: dict, env_path: Path):
except Exception as e:
logging.warning(f"Failed to write {key} to .env: {e}")
def setup() -> Path:
def setup():
base_dir = get_base_directory()
dirs = {
'config': base_dir / 'config',
@@ -172,4 +181,3 @@ def setup() -> Path:
write_config_to_env(merged_config, env_path)
return working_dir