flask发送错误日志到邮箱
2017-07-27 16:44
946 查看
loging 模块,无疑就是用来记录app在服务器中运行时所发生的错误信息,在flask中也不例外,先看以下代码
1:ErrorMail(将错误信息发送报告到指定邮箱里头,提醒管理员)
ADMINS = ['yourname@example.com']if not app.debug: import logging from logging.handlers import SMTPHandler mail_handler = SMTPHandler('127.0.0.1',
'server-error@example.com', ADMINS, 'YourApplication Failed') mail_handler.setLevel(logging.ERROR) app.logger.addHandler(mail_handler)
在debug模式为‘false’的服务器上,通过引入logging库文件,引入处理类 SMTPHander,当服务器中的app发生了错误报告时,会通过其设置的邮箱地址来将app的后天错误信息发送到指定的
server-error@example.com
邮箱中,提醒管理员后台出现错误信息,及时对错误信息进行处理。
2:logging to a file(将错误信息存储到文件当中去)
其中的属性设置如下:
i.FileHandler
将错误信息加入到一个文件系统的文件中去,
ii.RotatingFileHandler
将日志文件中的文本资料进行回滚处理、
iii.SysLogHandler
将日志信息发送到Unix系统文件中去
iV.NTEventLogHandler
将日志信息发送到windows系统文件中去
日志文件代码实例:
if not app.debug: import logging from themodule import TheHandlerYouWant file_handler = TheHandlerYouWant(...) file_handler.setLevel(logging.WARNING)
app.logger.addHandler(file_handler)
1:ErrorMail(将错误信息发送报告到指定邮箱里头,提醒管理员)
ADMINS = ['yourname@example.com']if not app.debug: import logging from logging.handlers import SMTPHandler mail_handler = SMTPHandler('127.0.0.1',
'server-error@example.com', ADMINS, 'YourApplication Failed') mail_handler.setLevel(logging.ERROR) app.logger.addHandler(mail_handler)
在debug模式为‘false’的服务器上,通过引入logging库文件,引入处理类 SMTPHander,当服务器中的app发生了错误报告时,会通过其设置的邮箱地址来将app的后天错误信息发送到指定的
server-error@example.com
邮箱中,提醒管理员后台出现错误信息,及时对错误信息进行处理。
2:logging to a file(将错误信息存储到文件当中去)
其中的属性设置如下:
i.FileHandler
将错误信息加入到一个文件系统的文件中去,
ii.RotatingFileHandler
将日志文件中的文本资料进行回滚处理、
iii.SysLogHandler
将日志信息发送到Unix系统文件中去
iV.NTEventLogHandler
将日志信息发送到windows系统文件中去
日志文件代码实例:
if not app.debug: import logging from themodule import TheHandlerYouWant file_handler = TheHandlerYouWant(...) file_handler.setLevel(logging.WARNING)
app.logger.addHandler(file_handler)
相关文章推荐
- android自己获取并保存错误日志(可以通过邮件发送到自己邮箱)
- Log4Net将错误日志发送到邮箱
- 错误日志自动发送至个人邮箱脚本
- log4net 发送错误日志到邮箱配置
- 发送错误日志到邮箱的两种方式
- logback配置错误日志发送邮件
- ios开发错误日志获取以及上传邮箱
- 使用django设置将错误报告发送到指定邮箱
- Android Uncaught Exception Handler邮件发送错误日志
- 导出系统日志并自动发送邮件到指定邮箱的一般方法(Windows server适用)
- C#通过电子邮件发送错误日志
- log4j 发送日志到邮箱
- 编写脚本:访问一网站,每5分钟访问一次,如果访问成功,将访问记录保存到日志,如果访问失败,则发送邮件至指定邮箱
- 配置完Exchange 2010 DAG出现owa能登陆邮箱但无法发送,outlook则出现以下文章的错误
- 配置日志logwarch 每天发送到邮箱
- 关于log4j将日志文件发送至邮箱的例子
- java qq 邮箱发送错误以及端口号
- Android Uncaught Exception Handler邮件发送错误日志
- PHP配置把错误日志以邮件方式发送方法(Windows系统)
- 2003获取系统日志并发送到邮箱