Refactor logging setup to use Loguru in WSGI and views for improved logging consistency and debugging

This commit is contained in:
Ross
2026-03-02 11:09:05 +00:00
parent 12e3d47600
commit 6ff8706fa4
2 changed files with 4 additions and 7 deletions
+1 -7
View File
@@ -197,7 +197,7 @@ import difflib
from helpers.cimar import CimarAPI from helpers.cimar import CimarAPI
logger = logging.getLogger(__name__) from loguru import logger
@login_required @login_required
@@ -903,7 +903,6 @@ def case_normal_form(request, pk):
}) })
# Log the rendered form HTML so we can verify inputs/names reach the client # Log the rendered form HTML so we can verify inputs/names reach the client
from loguru import logger
try: try:
form_html = form.as_p() form_html = form.as_p()
logger.debug("case_normal_form rendered form HTML: {}", form_html) logger.debug("case_normal_form rendered form HTML: {}", form_html)
@@ -926,7 +925,6 @@ def create_case_normal(request, pk):
return HttpResponse(status=403) return HttpResponse(status=403)
from .forms import NormalCaseForm from .forms import NormalCaseForm
from loguru import logger
form = NormalCaseForm(request.POST) form = NormalCaseForm(request.POST)
logger.debug("create_case_normal POST data: {}", dict(request.POST)) logger.debug("create_case_normal POST data: {}", dict(request.POST))
@@ -4801,10 +4799,6 @@ def series_dicom_json(request, pk):
def series_tags_partial(request, pk): def series_tags_partial(request, pk):
logger.info(f"Fetching tags for series {pk}") logger.info(f"Fetching tags for series {pk}")
try:
print(f"series_tags_partial hit: {pk}")
except Exception:
pass
# Accept either a numeric PK or a SeriesInstanceUID string # Accept either a numeric PK or a SeriesInstanceUID string
series = None series = None
try: try:
+3
View File
@@ -13,6 +13,7 @@ from django.core.wsgi import get_wsgi_application
from loguru import logger from loguru import logger
import sys import sys
from pathlib import Path from pathlib import Path
import logging
# Configure Loguru sinks early so app imports see consistent logging. # Configure Loguru sinks early so app imports see consistent logging.
# Log to stdout (so `docker logs` shows messages) and to a file at # Log to stdout (so `docker logs` shows messages) and to a file at
@@ -35,6 +36,8 @@ try:
serialize=True, serialize=True,
) )
logger.debug("Loguru logging configured with stdout and file sinks") logger.debug("Loguru logging configured with stdout and file sinks")
logging.root.setLevel(logging.DEBUG)
except Exception: except Exception:
# Best-effort only — don't crash WSGI startup if logging can't be configured # Best-effort only — don't crash WSGI startup if logging can't be configured
try: try: