From 4c37286b595944fe7cd197e657da4cb938b005a4 Mon Sep 17 00:00:00 2001 From: Corban-Lee Jones Date: Tue, 16 Jan 2024 16:53:27 +0000 Subject: [PATCH] Improved logging NOTE: when running without --noreload, there will be two log files, as Django runs two threads to make the auto reloading functionality work. --- core/settings.py | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/core/settings.py b/core/settings.py index d209685..80ccf5b 100644 --- a/core/settings.py +++ b/core/settings.py @@ -3,6 +3,9 @@ import os, environ from pathlib import Path +from django.utils import timezone + +now = timezone.now() env = environ.Env( # set casting, default value DEBUG=(bool, True) @@ -131,11 +134,13 @@ LOGGING = { 'file': { 'level': 'DEBUG', 'class': 'logging.FileHandler', - 'filename': LOGGING_DIR / 'debug.log', + 'filename': LOGGING_DIR / f'{now}.log', + "formatter": "verbose", }, 'console': { 'level': 'DEBUG', 'class': 'logging.StreamHandler', + "formatter": "verbose" }, }, 'loggers': { @@ -144,7 +149,22 @@ LOGGING = { 'level': 'INFO', 'propagate': True, }, + "django.request": { + "handlers": ["file", "console"], + "level": "ERROR", + "propagate": True + }, + "": { + "handlers": ["file", "console"], + "level": "DEBUG", + "propagate": True + } }, + "formatters": { + "verbose": { + "format": "[%(asctime)s] [%(levelname)s] [%(name)s]: %(message)s" # [%(asctime)s] [%(levelname)s] [%(name)s]: %(message)s + } + } } # Internationalization