From 037c2d08d8c15cd7f21a1df76ce63f1a205280f8 Mon Sep 17 00:00:00 2001 From: joe-nghiem-goldenowl Date: Mon, 25 Dec 2023 15:44:37 +0700 Subject: [PATCH] Configure logging --- django_template/settings/dev.py | 26 +++++++++++++++++++++++ django_template/settings/prod.py | 36 ++++++++++++++++++++++++++++++++ 2 files changed, 62 insertions(+) diff --git a/django_template/settings/dev.py b/django_template/settings/dev.py index 0fd6c04..7ef1e15 100644 --- a/django_template/settings/dev.py +++ b/django_template/settings/dev.py @@ -32,3 +32,29 @@ MIDDLEWARE.index("django.middleware.common.CommonMiddleware") + 1, "debug_toolbar.middleware.DebugToolbarMiddleware", ) + +# Logging +LOGGING = { + 'version': 1, + 'disable_existing_loggers': False, + 'formatters': { + 'standard': { + 'format': "[%(asctime)s] %(levelname)s [%(name)s:%(lineno)s] %(message)s", + 'datefmt': "%d/%b/%Y %H:%M:%S" + }, + }, + 'handlers': { + 'console': { + 'level': 'INFO', + 'class': 'logging.StreamHandler', + 'formatter': 'standard' + }, + }, + 'loggers': { + 'django': { + 'handlers': ['console'], + 'propagate': True, + 'level': 'INFO', + }, + } +} diff --git a/django_template/settings/prod.py b/django_template/settings/prod.py index 40227b6..801e6ac 100644 --- a/django_template/settings/prod.py +++ b/django_template/settings/prod.py @@ -36,3 +36,39 @@ ), ], ) + +# Logging +LOGGING = { + 'version': 1, + 'disable_existing_loggers': False, + 'formatters': { + 'standard': { + 'format': "[%(asctime)s] %(levelname)s [%(name)s:%(lineno)s] %(message)s", + 'datefmt': "%d/%b/%Y %H:%M:%S" + }, + }, + 'filters': { + 'require_debug_false': { + '()': 'django.utils.log.RequireDebugFalse' + } + }, + 'handlers': { + 'console': { + 'level': 'INFO', + 'class': 'logging.StreamHandler', + 'formatter': 'standard' + }, + 'sentry': { + 'level': 'ERROR', + 'filters': ['require_debug_false'], + 'class': 'raven.contrib.django.handlers.SentryHandler', + }, + }, + 'loggers': { + 'django': { + 'handlers': ['console', 'sentry'], + 'propagate': True, + 'level': 'INFO', + }, + } +}