From 27acf668df60f464443c57a4b124fb209cedf8b3 Mon Sep 17 00:00:00 2001 From: Joel Bradshaw Date: Mon, 17 Jan 2022 15:56:24 -0800 Subject: [PATCH] Add the required bits for Django's logger So, you can't define handlers piecewise, and if you redefine a logger, you have to also include everything it uses, because your "new" logger doesn't have a reference to the original logging config to get things like mail_admins and require_debug_false. require_debug_true isn't strictly necessary here, but it seemed strange to just copy over one of them. --- bookwyrm/settings.py | 28 ++++++++++++++++++++++++++-- 1 file changed, 26 insertions(+), 2 deletions(-) diff --git a/bookwyrm/settings.py b/bookwyrm/settings.py index 57a49df0..4ffded8c 100644 --- a/bookwyrm/settings.py +++ b/bookwyrm/settings.py @@ -110,18 +110,42 @@ LOG_LEVEL = env("LOG_LEVEL", "INFO").upper() # Override aspects of the default handler to our taste # See https://docs.djangoproject.com/en/3.2/topics/logging/#default-logging-configuration # for a reference to the defaults we're overriding +# +# It seems that in order to override anything you have to include its +# entire dependency tree (handlers and filters) which makes this a +# bit verbose LOGGING = { "version": 1, "disable_existing_loggers": False, + "filters": { + # These are copied from the default configuration, required for + # implementing mail_admins below + "require_debug_false": { + "()": "django.utils.log.RequireDebugFalse", + }, + "require_debug_true": { + "()": "django.utils.log.RequireDebugTrue", + }, + }, "handlers": { - # Overrides the default handler, which does not log in prod + # Overrides the default handler to make it log to console + # regardless of the DEBUG setting (default is to not log to + # console if DEBUG=False) "console": { "level": LOG_LEVEL, "class": "logging.StreamHandler", }, + # This is copied as-is from the default logger, and is + # required for the django section below + "mail_admins": { + "level": "ERROR", + "filters": ["require_debug_false"], + "class": "django.utils.log.AdminEmailHandler", + }, }, "loggers": { - # Override the log level for the default logger + # Install our new console handler for Django's logger, and + # override the log level while we're at it "django": { "handlers": ["console", "mail_admins"], "level": LOG_LEVEL,