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.
This commit is contained in:
Corban-Lee Jones 2024-01-16 16:53:27 +00:00
parent b52d1376d2
commit 4c37286b59

View File

@ -3,6 +3,9 @@
import os, environ import os, environ
from pathlib import Path from pathlib import Path
from django.utils import timezone
now = timezone.now()
env = environ.Env( env = environ.Env(
# set casting, default value # set casting, default value
DEBUG=(bool, True) DEBUG=(bool, True)
@ -131,11 +134,13 @@ LOGGING = {
'file': { 'file': {
'level': 'DEBUG', 'level': 'DEBUG',
'class': 'logging.FileHandler', 'class': 'logging.FileHandler',
'filename': LOGGING_DIR / 'debug.log', 'filename': LOGGING_DIR / f'{now}.log',
"formatter": "verbose",
}, },
'console': { 'console': {
'level': 'DEBUG', 'level': 'DEBUG',
'class': 'logging.StreamHandler', 'class': 'logging.StreamHandler',
"formatter": "verbose"
}, },
}, },
'loggers': { 'loggers': {
@ -144,7 +149,22 @@ LOGGING = {
'level': 'INFO', 'level': 'INFO',
'propagate': True, '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 # Internationalization