Skip to content

High performance self-hosted photo and video management solution.

fix(ml): move logging config to code (#32220)

bo0tzz655bfdb34fb7
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"
- ]
- }
-}