2016-08-25 28 views
1

我试图弄清楚为什么邮件不是从我从邮件工作的完美工作的应用程序复制的django应用程序发送的。我妄图让django在日志中吐出与邮件相关的东西,但没有出现。这里是我的设置settings.py中:如何在Django日志中查看与邮件有关的错误?

LOGGING = { 
    'version': 1, 
    'disable_existing_loggers': False, 
    'formatters': { 
     'verbose': { 
      'format': '%(levelname)s %(asctime)s %(module)s %(process)d %(thread)d %(message)s' 
     }, 
     'simple': { 
      'format': '%(levelname)s %(message)s' 
     }, 
    }, 
    'filters': { 
     'require_debug_false': { 
      '()': 'django.utils.log.RequireDebugFalse' 
     } 
    }, 
    'handlers': { 
     'mail_admins': { 
      'level': 'DEBUG', 
      'class': 'django.utils.log.AdminEmailHandler' 
     }, 
     'console': { 
      'level':'DEBUG', 
      'class':'logging.StreamHandler', 
      'formatter': 'simple' 
     }, 
     'file': { 
      'level': 'DEBUG', 
      'class': 'logging.FileHandler', 
      'filename': '/tmp/ooto.log', 
      'formatter': 'verbose' 
     }, 
    }, 
    'loggers': { 
     'django.request': { 
      'handlers': ['file'], 
      'level': 'DEBUG', 
      'propagate': True, 
     }, 
     'django_opensso':{ 
      'handlers' : ['file'], 
      'level' : 'DEBUG', 
     }, 
     'timekeeper':{ 
      'handlers' : ['file'], 
      'level' : 'DEBUG', 
     }, 
    } 

有人能详细解释或张贴的我怎么能收邮件相关的错误出Django的,所以我能解决现实问题的例子吗?

+0

从哪个应用程序发送邮件?它是'计时器'吗?如果是这样,在'INSTALLED_APPS'中是'timekeeper'吗? –

+0

是的,是的。 – Matthew

+0

'计时员'代码是否包含日志消息? –

回答

0

django.core.mailsmtplib都没有使用Pythons记录模块。 smtplib中有一个简单的日志记录工具,可以写入控制台。你必须设置运行.set_debuglevel(level)上的连接instace,其中level为整数> 0

应该有同样的结果:

import smtplib 
smtplib.SMTP.debuglevel = 9 

这是所谓的猴子补丁。要小心,它很难追查。

+0

假设邮件调用被封装在try/except中,并且日志在except中完成,则日志来自_his_代码,而不是直接来自邮件模块。 –

+0

@JohnGordon是的,这似乎是正确的。我今天要检查那些东西,如果必须注入我自己的日志记录! (虽然这不是我的代码,但我正在处理其他人的应用程序,但没有能够与他们交谈。):D – Matthew