Initial commit

This commit is contained in:
scoped
2026-05-15 02:41:52 +00:00
commit e2de5f705a
73 changed files with 9965 additions and 0 deletions

View File

@@ -0,0 +1,25 @@
from __future__ import annotations
import sys
import logging
from logging.handlers import RotatingFileHandler
from pathlib import Path
def configure_logging(log_dir: str, level: str) -> None:
Path(log_dir).mkdir(parents=True, exist_ok=True)
formatter = logging.Formatter("%(asctime)s %(levelname)s %(name)s %(message)s")
root = logging.getLogger()
root.setLevel(getattr(logging, level.upper(), logging.INFO))
root.handlers.clear()
stream = logging.StreamHandler()
stream.setFormatter(formatter)
root.addHandler(stream)
try:
file_handler = RotatingFileHandler(Path(log_dir) / "sortarr.log", maxBytes=5_000_000, backupCount=5)
file_handler.setFormatter(formatter)
root.addHandler(file_handler)
except OSError as exc:
print(f"Sortarr could not open file logging in {log_dir}: {exc}", file=sys.stderr)