From 428cd39d13c7ab2931a78de244b702bd4609ae40 Mon Sep 17 00:00:00 2001 From: Sonny Date: Sun, 26 Apr 2020 21:28:29 +0200 Subject: [PATCH] 0.2.2.1 - Update logging settings - Add admins setting --- src/newsreader/celery.py | 6 +-- src/newsreader/conf/base.py | 67 +++++++++++++++++++++++++++++++ src/newsreader/conf/production.py | 8 +++- 3 files changed, 75 insertions(+), 6 deletions(-) diff --git a/src/newsreader/celery.py b/src/newsreader/celery.py index aa15a08..3eb59e0 100644 --- a/src/newsreader/celery.py +++ b/src/newsreader/celery.py @@ -3,12 +3,8 @@ import os from celery import Celery -# note: this should be consistent with the setting from manage.py os.environ.setdefault("DJANGO_SETTINGS_MODULE", "newsreader.conf.dev") -# note: use the --workdir flag when running from different directories app = Celery("newsreader") - -app.config_from_object("django.conf:settings") - +app.config_from_object("django.conf:settings", namespace="CELERY") app.autodiscover_tasks() diff --git a/src/newsreader/conf/base.py b/src/newsreader/conf/base.py index 743973d..3692deb 100644 --- a/src/newsreader/conf/base.py +++ b/src/newsreader/conf/base.py @@ -94,6 +94,69 @@ CACHES = { }, } +# Logging +# https://docs.djangoproject.com/en/2.2/topics/logging/#configuring-logging +LOGGING = { + "version": 1, + "disable_existing_loggers": False, + "filters": { + "require_debug_false": {"()": "django.utils.log.RequireDebugFalse"}, + "require_debug_true": {"()": "django.utils.log.RequireDebugTrue"}, + }, + "formatters": { + "django.server": { + "()": "django.utils.log.ServerFormatter", + "format": "[{server_time}] {message}", + "style": "{", + }, + "syslog": {"class": "logging.Formatter", "format": "{message}", "style": "{"}, + }, + "handlers": { + "console": { + "level": "INFO", + "filters": ["require_debug_true"], + "class": "logging.StreamHandler", + }, + "django.server": { + "level": "INFO", + "class": "logging.StreamHandler", + "formatter": "django.server", + }, + "mail_admins": { + "level": "ERROR", + "filters": ["require_debug_false"], + "class": "django.utils.log.AdminEmailHandler", + }, + "syslog": { + "level": "INFO", + "filters": ["require_debug_false"], + "class": "logging.handlers.SysLogHandler", + "formatter": "syslog", + "address": "/dev/log", + }, + "syslog_errors": { + "level": "ERROR", + "filters": ["require_debug_false"], + "class": "logging.handlers.SysLogHandler", + "formatter": "syslog", + "address": "/dev/log", + }, + }, + "loggers": { + "django": { + "handlers": ["console", "mail_admins", "syslog_errors"], + "level": "INFO", + }, + "django.server": { + "handlers": ["django.server"], + "level": "INFO", + "propagate": False, + }, + "celery": {"handlers": ["syslog", "console"], "level": "INFO"}, + "celery.task": {"handlers": ["syslog", "console"], "level": "INFO"}, + }, +} + # Password validation # https://docs.djangoproject.com/en/2.2/ref/settings/#auth-password-validators AUTH_PASSWORD_VALIDATORS = [ @@ -155,6 +218,10 @@ SWAGGER_SETTINGS = { "DOC_EXPANSION": "list", } +# Celery +# https://docs.celeryproject.org/en/stable/userguide/configuration.html +CELERY_WORKER_HIJACK_ROOT_LOGGER = False + REGISTRATION_OPEN = True REGISTRATION_AUTO_LOGIN = True ACCOUNT_ACTIVATION_DAYS = 7 diff --git a/src/newsreader/conf/production.py b/src/newsreader/conf/production.py index f287498..b5c766a 100644 --- a/src/newsreader/conf/production.py +++ b/src/newsreader/conf/production.py @@ -9,7 +9,13 @@ from .base import * # isort:skip load_dotenv() DEBUG = False + ALLOWED_HOSTS = ["rss.fudiggity.nl"] +ADMINS = [ + ("", email) + for email in os.getenv("ADMINS", "").split(",") + if os.environ.get("ADMINS") +] SECRET_KEY = os.environ["DJANGO_SECRET_KEY"] @@ -40,6 +46,6 @@ TEMPLATES = [ ] # Third party settings -AXES_HANDLER = "axes.handlers.database.DatabaseHandler" +AXES_HANDLER = "axes.handlers.database.AxesDatabaseHandler" REGISTRATION_OPEN = False