Добавил логирование для отправщика емейлов.

remotes/origin/stage5
Alexander Burdeiny 10 years ago
parent 5644383774
commit d7e38dac9d
  1. 6
      emencia/django/newsletter/mailer.py
  2. 35
      support/dev/settings.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()

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

Loading…
Cancel
Save