flask-logging flask的日志文件功能


  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)





机械设计制造及其自动化


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM