'Django logging errors into seperate files by timestamp
I have set up a Django log successfully with the following code:
LOGGING = {
'version': 1,
'disable_existing_loggers': False,
'handlers': {
'file': {
'level': 'ERROR',
'class': 'logging.FileHandler',
'filename': 'debug.log',
},
},
'loggers': {
'django': {
'handlers': ['file'],
'level': 'ERROR',
'propagate': True,
},
},
}
And from this, I'm able to find errors logged in the 'debug.log' file that's define above.
However what I'd like to achieve is that any Django error is sent to an individual and timestamped log file. For example, if a ValueError is encountered, it would save it to a file named something like: debug_2022-03-04_1143.log
I searched some other answers on this, but most seemed to be talking about timestamping at logged intervals, and I couldn't find a solution to the objective I listed above. Any help is appreciated.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
