My log.django file is over 100,000 lines now. If I delete it, will it be re-generated again? It exists because I have LOGGING in my settings.py:
LOGGING = {
'version': 1,
'disable_existing_loggers': False,
'handlers': {
'console': {
'class': 'logging.StreamHandler',
},
'file': {
'level': 'DEBUG',
'class': 'logging.FileHandler',
'filename': 'log.django',
},
},
'loggers': {
'django': {
'handlers': ['console', 'file'],
'level': os.getenv('DJANGO_LOG_LEVEL', 'DEBUG'),
},
},
}
Log file cannot be re-generated. It consists of events that occurred in the past. But if you deleted it, a new one will be generated.
I suggest you set RotatingFileHandler logging handler, the maximum size for the log file and a number of backups to be kept. This way once the file reaches maximum size, current log file will be renamed and a new log file will be created.
Django uses dictConfig scheme for logging configuration. For rotating file handler with maximum size of about 2MB and 2 backup log files, you'd define file key in handlers as:
'file': {
'level': 'DEBUG',
'class': 'logging.handlers.RotatingFileHandler',
'filename': 'log.django',
'maxBytes': 2000000,
'backupCount': 2
},
This way current log.django will be renamed to log.django.1 once it reaches size of 2.000.000 bytes and 2 backup files will be kept (log.django.1 and log.django.2) at all times.
If you add maxBytes and backupCount to your current configuration, your current log file will be renamed to log.django.1 and a new log.django will be created.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With