From d7e38dac9d416126ac7d08ac76e246914598057b Mon Sep 17 00:00:00 2001 From: Alexander Burdeiny Date: Thu, 21 Jul 2016 12:22:07 +0300 Subject: [PATCH] =?UTF-8?q?=D0=94=D0=BE=D0=B1=D0=B0=D0=B2=D0=B8=D0=BB=20?= =?UTF-8?q?=D0=BB=D0=BE=D0=B3=D0=B8=D1=80=D0=BE=D0=B2=D0=B0=D0=BD=D0=B8?= =?UTF-8?q?=D0=B5=20=D0=B4=D0=BB=D1=8F=20=D0=BE=D1=82=D0=BF=D1=80=D0=B0?= =?UTF-8?q?=D0=B2=D1=89=D0=B8=D0=BA=D0=B0=20=D0=B5=D0=BC=D0=B5=D0=B9=D0=BB?= =?UTF-8?q?=D0=BE=D0=B2.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- emencia/django/newsletter/mailer.py | 6 ++++- support/dev/settings.py | 35 +++++++++++++++++++++++++++-- 2 files changed, 38 insertions(+), 3 deletions(-) diff --git a/emencia/django/newsletter/mailer.py b/emencia/django/newsletter/mailer.py index 36e44c14..968e99cc 100644 --- a/emencia/django/newsletter/mailer.py +++ b/emencia/django/newsletter/mailer.py @@ -14,6 +14,8 @@ from datetime import timedelta from smtplib import SMTPRecipientsRefused from pymorphy2 import MorphAnalyzer morph = MorphAnalyzer() +from logging import getLogger +log = getLogger('mail') try: from email.mime.multipart import MIMEMultipart @@ -471,8 +473,8 @@ class Mailer(NewsLetterSender): announce_context = contact.get_announce_context() if self.announce else None if self.announce and not announce_context: send = False - try: + log.info('Trying send to {email}'.format(email=contact.email)) # pass if send: message = self.build_message(contact, announce_context) @@ -481,6 +483,8 @@ class Mailer(NewsLetterSender): message.as_string()) except (Exception, ) as e: exception = e + log.info('Exception was raised while sending to {email}: {exception}'.format( + email=contact.email, exception=exception)) else: exception = None self.update_ab_state() diff --git a/support/dev/settings.py b/support/dev/settings.py index 8daef901..fd515035 100644 --- a/support/dev/settings.py +++ b/support/dev/settings.py @@ -548,5 +548,36 @@ if DEBUG: ] - - +# logging +U_LOGFILE_SIZE = 1 * 1024 * 1024 +U_LOGFILE_COUNT = 2 +DEFAULT_LOGGER_NAME = 'mail' +LOGGING = { + 'version': 1, + 'disable_existing_loggers': False, + 'formatters': { + 'verbose': { + 'format': '%(levelname)s %(asctime)s %(module)s %(process)d %(thread)d %(message)s \n' + }, + 'simple': { + 'format': '%(levelname)s %(message)s' + }, + }, + 'handlers': { + 'file': { + 'level': 'INFO', + 'filename': os.path.join(SITE_ROOT, 'logs/django.log'), + 'formatter': 'verbose', + 'class':'logging.handlers.RotatingFileHandler', + 'maxBytes': U_LOGFILE_SIZE, + 'backupCount': U_LOGFILE_COUNT, + }, + }, + 'loggers': { + 'mail': { + 'handlers': ['file'], + 'propagate': True, + 'level': 'DEBUG', + }, + } +}