Skip to content

Instantly share code, notes, and snippets.

@happygrizzly
Created November 16, 2023 17:10
Show Gist options
  • Save happygrizzly/97efded0289456ad29a3bffa86e7dd2f to your computer and use it in GitHub Desktop.
Save happygrizzly/97efded0289456ad29a3bffa86e7dd2f to your computer and use it in GitHub Desktop.
Logging config
LOGGING = {
'version': 1,
'disable_existing_loggers': False,
'formatters': {
'default': {
'format': "[%(asctime)s] %(levelname)s [%(name)s:%(lineno)s] %(message)s",
'datefmt': "%d/%b/%Y %H:%M:%S",
},
'sql': {
'format': "[%(asctime)s] %(levelname)s [%(module)s:%(lineno)s] %(message)s",
'datefmt': "%d/%b/%Y %H:%M:%S"
},
},
'handlers': {
'file': {
'class': 'logging.handlers.RotatingFileHandler',
'filename': os.path.join(os.getenv('DJANGO_LOG_PATH', BASE_DIR), 'django.default.log'),
'maxBytes': 10 * 1024 * 1024,
'backupCount': 5,
'formatter': 'default',
},
'sql': {
'class': 'logging.handlers.RotatingFileHandler',
'filename': os.path.join(os.getenv('DJANGO_LOG_PATH', BASE_DIR), 'django.sql.log'),
'maxBytes': 10 * 1024 * 1024,
'backupCount': 5,
'level': 'DEBUG',
'formatter': 'sql',
},
},
'loggers': {
'django.db.backends': {
'handlers': ['sql'],
'level': 'DEBUG',
'propagate': False,
},
},
'root': {
'handlers': ['file'],
'level': os.getenv('DJANGO_LOG_LEVEL', 'WARNING'),
'propagate': False,
},
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment