From 8ee3f561a4300e1b39b0ef90ac9e0d27111ed602 Mon Sep 17 00:00:00 2001 From: Cayo Puigdefabregas Date: Fri, 15 Dec 2023 14:08:03 +0100 Subject: [PATCH] use logging correctly --- idhub/email/views.py | 12 +++++++++--- trustchain_idhub/settings.py | 15 +++++++++++++++ 2 files changed, 24 insertions(+), 3 deletions(-) diff --git a/idhub/email/views.py b/idhub/email/views.py index 83d10cc..72e0daa 100644 --- a/idhub/email/views.py +++ b/idhub/email/views.py @@ -1,3 +1,5 @@ +import logging + from django.conf import settings from django.template import loader from django.core.mail import EmailMultiAlternatives @@ -7,6 +9,9 @@ from django.utils.encoding import force_bytes from django.utils.http import urlsafe_base64_encode +logger = logging.getLogger(__name__) + + class NotifyActivateUserByEmail: def get_email_context(self, user): """ @@ -49,10 +54,11 @@ class NotifyActivateUserByEmail: email_message.attach_alternative(html_email, 'text/html') try: if settings.DEVELOPMENT: - print(to_email) - print(body) + logger.warning(to_email) + logger.warning(body) return email_message.send() - except Exception: + except Exception as err: + logger.error(err) return diff --git a/trustchain_idhub/settings.py b/trustchain_idhub/settings.py index 7601739..b9eecc5 100644 --- a/trustchain_idhub/settings.py +++ b/trustchain_idhub/settings.py @@ -207,3 +207,18 @@ SUPPORTED_CREDENTIALS = config( default='[]', cast=literal_eval ) + +LOGGING = { + "version": 1, + "disable_existing_loggers": False, + "handlers": { + "console": {"class": "logging.StreamHandler"}, + }, + "loggers": { + "django": { + "handlers": ["console"], + "level": "INFO", + }, + } +} +