From 69c9faa4bc36ae7bba439e0f6610fd980fe09dbc Mon Sep 17 00:00:00 2001 From: Luca Date: Sun, 12 May 2024 22:08:41 +0200 Subject: [PATCH] chore: add custom logging config --- shiftregister/messaging/backends/dummy.py | 3 ++- shiftregister/settings.py | 20 ++++++++++++++++++++ 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/shiftregister/messaging/backends/dummy.py b/shiftregister/messaging/backends/dummy.py index dc50ed0..b3483c7 100644 --- a/shiftregister/messaging/backends/dummy.py +++ b/shiftregister/messaging/backends/dummy.py @@ -41,7 +41,8 @@ class WebhookReceiver(BaseReceiver): if not sender: raise ValueError("message has no sender") - logging.getLogger("django.server").info( + logger.info( f"received sms via webhook\nkey: {key}\nfrom: {sender}\nadditional fields: {pformat(kwargs)}\n\n{text}" ) + yield Message(key, sender=sender, text=text, type=MessageType.INBOUND) diff --git a/shiftregister/settings.py b/shiftregister/settings.py index f66b04f..79dbe4b 100644 --- a/shiftregister/settings.py +++ b/shiftregister/settings.py @@ -240,3 +240,23 @@ SMS_OUTBOUND_BACKEND = ".".join( ) SMS_SETTINGS = env.dict("SMS_SETTINGS", default={}) SMS_WEBHOOK_SECRET = env("SMS_WEBHOOK_SECRET", default=None) + +# Logging +# https://docs.djangoproject.com/en/5.0/howto/logging/#customize-logging-configuration + +LOGGING = { + "version": 1, + "disable_existing_loggers": False, + "handlers": { + "console": { + "level": "DEBUG" if DEBUG else "WARNING", + "class": "logging.StreamHandler", + }, + }, + "loggers": { + "shiftregister": { + "level": "DEBUG" if DEBUG else "WARNING", + "handlers": ["console"], + }, + }, +}