2
0
mirror of https://expo.survex.com/repositories/troggle/.git synced 2026-03-01 03:01:41 +00:00

Now set up full Django logging for 404

This commit is contained in:
2026-02-13 16:41:27 +00:00
parent 4d5b21dfce
commit 3c40720a95
2 changed files with 80 additions and 2 deletions

View File

@@ -1,3 +1,4 @@
import logging
import os
import re
from datetime import datetime
@@ -294,6 +295,7 @@ def expopage(request, path):
"""Either renders an HTML page from expoweb with all the menus,
or serves an unadorned binary file with mime type
"""
logger = logging.getLogger('troggle')
# print(" - EXPOPAGES delivering the file: '{}':{} as MIME type: {}".format(request.path, path,getmimetype(path)),flush=True)
if path.startswith("noinfo") and settings.PUBLIC_SITE and not request.user.is_authenticated:
@@ -342,11 +344,15 @@ def expopage(request, path):
return HttpResponse(content=content, content_type=content_type)
except FileNotFoundError as e:
message = f" ! - 404 FileNotFound REMOTE_ADDR: {meta['REMOTE_ADDR']:>15} [{stamp}] '/{path}'"
DataIssue.objects.create(parser="view404", message=message)
#DataIssue.objects.create(parser="view404", message=message)
logmsg = f"[{meta['REMOTE_ADDR']:>15}] '/{path}' FILE NOT FOUND 404"
logger.warning(logmsg)
return render(request, "pagenotfound.html", {"path": path}, status=404)
except Exception as e:
message = f" ! - 404? REMOTE_ADDR: {meta['REMOTE_ADDR']:>15} [{stamp}] '/{path}' {e}"
DataIssue.objects.create(parser="view404", message=message)
#DataIssue.objects.create(parser="view404", message=message)
logmsg = f"[{meta['REMOTE_ADDR']:>15}] '/{path}' FILE NOT FOUND 404"
logger.warning(logmsg)
return render(request, "pagenotfound.html", {"path": path}, status=404)