fix logs (and import)
This commit is contained in:
@@ -636,11 +636,9 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
const casePk = trigger.dataset.caseId || importCaseId;
|
const casePk = trigger.dataset.caseId || importCaseId;
|
||||||
if (!casePk) {
|
const confirmMsg = casePk
|
||||||
alert('Could not determine a target case for this partial import. Use an "Import remaining" button linked to a case or open this page in a case context.');
|
? `Finish importing ${seriesUids.length} series into case ${casePk}?`
|
||||||
return;
|
: `Finish importing ${seriesUids.length} series without linking to a case?`;
|
||||||
}
|
|
||||||
const confirmMsg = `Finish importing ${seriesUids.length} series${casePk ? ` into case ${casePk}` : ''}?`;
|
|
||||||
if (!window.confirm(confirmMsg)) return;
|
if (!window.confirm(confirmMsg)) return;
|
||||||
|
|
||||||
await runImport(seriesUids, casePk);
|
await runImport(seriesUids, casePk);
|
||||||
|
|||||||
@@ -66,7 +66,7 @@ if not DEBUG:
|
|||||||
'file': {
|
'file': {
|
||||||
'level': 'DEBUG',
|
'level': 'DEBUG',
|
||||||
'class': 'logging.FileHandler',
|
'class': 'logging.FileHandler',
|
||||||
'filename': 'log.txt',
|
'filename': 'logs/app.log',
|
||||||
'formatter': 'verbose',
|
'formatter': 'verbose',
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -33,7 +33,7 @@ if not DEBUG:
|
|||||||
'file': {
|
'file': {
|
||||||
'level': 'DEBUG',
|
'level': 'DEBUG',
|
||||||
'class': 'logging.FileHandler',
|
'class': 'logging.FileHandler',
|
||||||
'filename': 'log.txt',
|
'filename': 'logs/app.log',
|
||||||
'formatter': 'verbose',
|
'formatter': 'verbose',
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -50,9 +50,13 @@ def _get_log_file_path() -> Path:
|
|||||||
pass
|
pass
|
||||||
|
|
||||||
try:
|
try:
|
||||||
return Path(getattr(settings, "BASE_DIR", Path.cwd())) / "log.txt"
|
return Path(getattr(settings, "BASE_DIR", Path.cwd())) / "logs" / "app.log"
|
||||||
except Exception:
|
except Exception:
|
||||||
return Path.cwd() / "log.txt"
|
return Path.cwd() / "logs" / "app.log"
|
||||||
|
|
||||||
|
|
||||||
|
def get_log_file_path() -> Path:
|
||||||
|
return _get_log_file_path()
|
||||||
|
|
||||||
|
|
||||||
def configure_loguru() -> Path:
|
def configure_loguru() -> Path:
|
||||||
@@ -60,7 +64,7 @@ def configure_loguru() -> Path:
|
|||||||
if _CONFIGURED:
|
if _CONFIGURED:
|
||||||
return _get_log_file_path()
|
return _get_log_file_path()
|
||||||
|
|
||||||
log_file_path = _get_log_file_path()
|
log_file_path = get_log_file_path()
|
||||||
log_file_path.parent.mkdir(parents=True, exist_ok=True)
|
log_file_path.parent.mkdir(parents=True, exist_ok=True)
|
||||||
stdout_level = _get_stdout_level()
|
stdout_level = _get_stdout_level()
|
||||||
log_format = "[{time:DD/MMM/YYYY HH:mm:ss}] {level} [{name}:{line}] {message}"
|
log_format = "[{time:DD/MMM/YYYY HH:mm:ss}] {level} [{name}:{line}] {message}"
|
||||||
|
|||||||
@@ -24,13 +24,13 @@ def test_loguru_uses_django_file_handler_path(settings, tmp_path, monkeypatch):
|
|||||||
def test_logs_view_filters_by_date_and_can_reset_log_file(client, admin_user, monkeypatch, tmp_path):
|
def test_logs_view_filters_by_date_and_can_reset_log_file(client, admin_user, monkeypatch, tmp_path):
|
||||||
client.force_login(admin_user)
|
client.force_login(admin_user)
|
||||||
|
|
||||||
log_file = tmp_path / "log.txt"
|
log_file = tmp_path / "app.log"
|
||||||
log_file.write_text(
|
log_file.write_text(
|
||||||
"[03/Jun/2026 10:00:00] INFO [atlas.views:10] first entry\n"
|
"[03/Jun/2026 10:00:00] INFO [atlas.views:10] first entry\n"
|
||||||
"[03/Jun/2026 11:00:00] ERROR [atlas.views:11] second entry\n",
|
"[03/Jun/2026 11:00:00] ERROR [atlas.views:11] second entry\n",
|
||||||
encoding="utf-8",
|
encoding="utf-8",
|
||||||
)
|
)
|
||||||
monkeypatch.setattr("rad.views.settings.BASE_DIR", str(tmp_path))
|
monkeypatch.setattr("rad.views.get_log_file_path", lambda: log_file)
|
||||||
|
|
||||||
response = client.get(
|
response = client.get(
|
||||||
reverse("logs_view"),
|
reverse("logs_view"),
|
||||||
|
|||||||
+4
-3
@@ -105,6 +105,7 @@ from django.db.models import Q
|
|||||||
from dal import autocomplete
|
from dal import autocomplete
|
||||||
|
|
||||||
from loguru import logger
|
from loguru import logger
|
||||||
|
from .logging_setup import get_log_file_path
|
||||||
|
|
||||||
import psutil
|
import psutil
|
||||||
|
|
||||||
@@ -295,13 +296,13 @@ def account_send_password_reset(request, slug):
|
|||||||
|
|
||||||
@user_passes_test(lambda u: u.is_superuser)
|
@user_passes_test(lambda u: u.is_superuser)
|
||||||
def logs_view(request):
|
def logs_view(request):
|
||||||
"""Display production logs from log.txt with search filtering.
|
"""Display production logs with search/filter controls.
|
||||||
|
|
||||||
Scope: superusers only.
|
Scope: superusers only.
|
||||||
Functionality: reads log.txt, displays entries with optional text search filter.
|
Functionality: reads the configured application log file and displays entries with optional text search filter.
|
||||||
Supports ?all=1 to show all entries without pagination limit.
|
Supports ?all=1 to show all entries without pagination limit.
|
||||||
"""
|
"""
|
||||||
log_file_path = os.path.join(settings.BASE_DIR, "log.txt")
|
log_file_path = str(get_log_file_path())
|
||||||
search_query = request.GET.get("q", "").strip()
|
search_query = request.GET.get("q", "").strip()
|
||||||
level_filter = request.GET.get("level", "").strip().upper()
|
level_filter = request.GET.get("level", "").strip().upper()
|
||||||
show_all = request.GET.get("all") == "1"
|
show_all = request.GET.get("all") == "1"
|
||||||
|
|||||||
Reference in New Issue
Block a user