From 655bfdb34fb7f7f930d74fa099ff65d0b40280d0 Mon Sep 17 00:00:00 2001 From: bo0tzz Date: Thu, 8 Oct 2026 16:41:09 +0200 Subject: [PATCH] fix(ml): move logging config to code (#32220) This lets it be applied earlier on, so the initializing [version] log line actually works. --- machine-learning/immich_ml/__main__.py | 2 -- machine-learning/immich_ml/config.py | 11 +++++++++++ machine-learning/immich_ml/gunicorn_conf.py | 4 ++++ machine-learning/immich_ml/log_conf.json | 21 --------------------- 4 files changed, 15 insertions(+), 23 deletions(-) delete mode 100644 machine-learning/immich_ml/log_conf.json diff --git a/machine-learning/immich_ml/__main__.py b/machine-learning/immich_ml/__main__.py index 49e37aae94..c5aeeba183 100644 --- a/machine-learning/immich_ml/__main__.py +++ b/machine-learning/immich_ml/__main__.py @@ -48,8 +48,6 @@ try: str(settings.workers), "-t", str(settings.worker_timeout), - "--log-config-json", - module_dir / "log_conf.json", "--keep-alive", str(settings.http_keepalive_timeout_s), "--graceful-timeout", diff --git a/machine-learning/immich_ml/config.py b/machine-learning/immich_ml/config.py index b4b438605d..70e0023f41 100644 --- a/machine-learning/immich_ml/config.py +++ b/machine-learning/immich_ml/config.py @@ -1,9 +1,11 @@ import concurrent.futures import logging +import logging.config import os import sys from pathlib import Path from socket import socket +from typing import Any from gunicorn.arbiter import Arbiter from pydantic import BaseModel, Field @@ -144,6 +146,15 @@ class CustomRichHandler(RichHandler): return super().emit(record) +LOG_CONFIG: dict[str, Any] = { + "version": 1, + "disable_existing_loggers": False, + "handlers": {"console": {"()": CustomRichHandler}}, + "loggers": {"gunicorn.error": {"handlers": ["console"]}}, + "root": {"handlers": ["console"]}, +} +logging.config.dictConfig(LOG_CONFIG) + log = logging.getLogger("ml.log") log.setLevel(LOG_LEVEL) diff --git a/machine-learning/immich_ml/gunicorn_conf.py b/machine-learning/immich_ml/gunicorn_conf.py index efec3a95aa..255c6050df 100644 --- a/machine-learning/immich_ml/gunicorn_conf.py +++ b/machine-learning/immich_ml/gunicorn_conf.py @@ -3,9 +3,13 @@ import os from gunicorn.arbiter import Arbiter from gunicorn.workers.base import Worker +from immich_ml.config import LOG_CONFIG + device_ids = os.environ.get("MACHINE_LEARNING_DEVICE_IDS", "0").replace(" ", "").split(",") env = os.environ +logconfig_dict = LOG_CONFIG + # Round-robin device assignment for each worker def pre_fork(arbiter: Arbiter, _: Worker) -> None: diff --git a/machine-learning/immich_ml/log_conf.json b/machine-learning/immich_ml/log_conf.json deleted file mode 100644 index d30b86d486..0000000000 --- a/machine-learning/immich_ml/log_conf.json +++ /dev/null @@ -1,21 +0,0 @@ -{ - "version": 1, - "disable_existing_loggers": false, - "handlers": { - "console": { - "class": "immich_ml.config.CustomRichHandler" - } - }, - "loggers": { - "gunicorn.error": { - "handlers": [ - "console" - ] - } - }, - "root": { - "handlers": [ - "console" - ] - } -}