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', + }, + } +}