fix timezone

This commit is contained in:
Aron Petau 2026-01-04 11:26:43 +01:00
parent f761f7b7e8
commit 743508ca66
3 changed files with 34 additions and 8 deletions

26
main.py
View file

@ -10,20 +10,36 @@ from dotenv import load_dotenv
from state_manager import StateManager
from pathlib import Path
from autoclean_debug import autoclean_debug_material
from datetime import datetime, timezone
import time
# --- Environment & Logging Setup ---
# Load environment variables from .env file
load_dotenv()
# Custom formatter with Berlin timezone (UTC+1)
class BerlinFormatter(logging.Formatter):
def formatTime(self, record, datefmt=None):
dt = datetime.fromtimestamp(record.created, tz=timezone.utc)
# Berlin is UTC+1 (CET) or UTC+2 (CEST), using UTC+1 for simplicity
berlin_dt = dt.astimezone(timezone(timedelta(hours=1)))
if datefmt:
return berlin_dt.strftime(datefmt)
return berlin_dt.strftime("%Y-%m-%d %H:%M:%S,%f")[:-3]
from datetime import timedelta
# Configure logging: file (rotating) + console for Docker visibility, enforce for all modules
file_handler = RotatingFileHandler("data/monitor.log", maxBytes=1 * 1024 * 1024, backupCount=3)
file_handler.setFormatter(BerlinFormatter("%(asctime)s [%(levelname)-5s] %(name)-20s | %(message)s"))
console_handler = logging.StreamHandler()
console_handler.setFormatter(BerlinFormatter("%(asctime)s [%(levelname)-5s] %(name)-20s | %(message)s"))
logging.basicConfig(
level=logging.INFO,
format="%(asctime)s [%(levelname)-5s] %(name)-20s | %(message)s",
handlers=[
RotatingFileHandler("data/monitor.log", maxBytes=1 * 1024 * 1024, backupCount=3),
logging.StreamHandler()
],
handlers=[file_handler, console_handler],
force=True # Enforce for all modules, Python 3.8+
)
logger = logging.getLogger(__name__) # Use named logger