10👍
maxBytes
is an attribute of the RotatingFileHandler
not the FileHandler
. You will need to modify your logging config to:
'file_database': {
'level': 'DEBUG',
'class': 'logging.handlers.RotatingFileHandler', # Use RotatingFileHandler
'filename': os.path.join(BASE_DIR, 'logs/database.log'),
'maxBytes': 1024 * 1024 * 10, # 10 MB
},
Note that the package is logging.handlers
.
0👍
From django doc, you can also set backupCount to keep multiple files.
LOGGING = {
'version': 1,
'disable_existing_loggers': False,
'formatters': {
'verbose': {
'format': '{levelname} {asctime} {module} {process:d} {thread:d} {message}',
'style': '{',
},
},
'handlers': {
'debugRotatingFileHandler': {
'level':'DEBUG',
'class':'logging.handlers.RotatingFileHandler',
'formatter': 'verbose',
'maxBytes': 1024*1024*1000, # 1000 MB
'backupCount': 0, # Keep 1 file
'filename': os.path.join(BASE_DIR, 'django.log'),
},
},
'loggers': {
'django': {
'handlers': ['debugRotatingFileHandler'],
'level': 'DEBUG',
'propagate': True,
},
}
}
- [Django]-Django/Python convert PDF using shell (os.system/Popen) not working in production
- [Django]-Changing settings for the tests in django (search engine for haystack to be specific)
- [Django]-Authenticate() function not working django.contrib.auth
- [Django]-Passing a Django database pk id to Dash app
Source:stackexchange.com