python使用logging模块发送邮件代码示例,pythonlogging
python使用logging模块发送邮件代码示例,pythonlogging
logging模块不只是能记录log,还能发送邮件,使用起来非常简单方便
#coding=utf-8 ''''' Created on 2016-3-21 @author: Administrator ''' import logging, logging.handlers class EncodingFormatter(logging.Formatter): def __init__(self, fmt, datefmt=None, encoding=None): logging.Formatter.__init__(self, fmt, datefmt) self.encoding = encoding def format(self, record): result = logging.Formatter.format(self, record) if isinstance(result, unicode): result = result.encode(self.encoding or 'utf-8') return result #zhangdongsheng@itouzi.com errlog = logging.getLogger() sh = logging.handlers.SMTPHandler("smtp.163.com", 'xigongda200608@163.com', '381084992@qq.com', "logging from my app", credentials=('xigongda200608', 'password'), secure=()) errlog.addHandler(sh) sh.setFormatter(EncodingFormatter('%(message)s', encoding='utf-8')) errlog.error(u'追加文件时出错')
总结
以上就是本文关于python使用logging模块发送邮件代码示例的全部内容,希望对大家有所帮助。感兴趣的朋友可以继续参阅本站其他相关专题,如有不足之处,欢迎留言指出。感谢朋友们对本站的支持!
相关内容
- Python基于高斯消元法计算线性方程组示例,python线性方
- 快速了解Python开发中的cookie及简单代码示例,pythoncoo
- Python线性方程组求解运算示例,python线性方程组
- python根据unicode判断语言类型实例代码,python语言类型
- Python工程师面试必备25条知识点,python25条
- Python元字符的用法实例解析,python用法实例
- Python tornado队列示例-一个并发web爬虫代码分享,python
- python删除过期log文件操作实例解析,
- python+matplotlib实现礼盒柱状图实例代码,pythonmatplotlib
- Python使用matplotlib填充图形指定区域代码示例,pythonma
评论关闭