#! /usr/bin/env python
#coding=utf-8
import logging,os class Logger:
def __init__(self, path,clevel = logging.DEBUG,Flevel = logging.DEBUG):
self.logger = logging.getLogger(path)
self.logger.setLevel(logging.DEBUG)
fmt = logging.Formatter('[%(asctime)s] [%(levelname)s] %(message)s', '%Y-%m-%d %H:%M:%S')
#设置CMD日志
sh = logging.StreamHandler()
sh.setFormatter(fmt)
sh.setLevel(clevel)
#设置文件日志
fh = logging.FileHandler(path)
fh.setFormatter(fmt)
fh.setLevel(Flevel)
self.logger.addHandler(sh)
self.logger.addHandler(fh) def debug(self,message):
self.logger.debug(message) def info(self,message):
self.logger.info(message) def war(self,message):
self.logger.warning(message) def error(self,message):
self.logger.error(message) def cri(self,message):
self.logger.critical(message) if __name__ =='__main__':
log_mu = Logger('file_path',logging.DEBUG,logging.DEBUG)
# log_mu.debug('一个debug信息')
log_mu.info('一个info信息')
# log_mu.war('一个warning信息')
# log_mu.error('一个error信息')
# log_mu.cri('一个致命critical信息') # 读日志文件的时候必须用gbk方式解码
# with open('file_path','r',encoding='gbk') as f:
# print(f.read().strip())

最新文章

  1. 使用weave管理docker网络
  2. html5 定位 获得当前位置的经纬度
  3. Practical JAVA(二)关于对象的类型和equals函数
  4. Linux编辑器vi使用方法详细介绍
  5. WCF的行为与异常-------配置文件说明
  6. iOS OC开发代码规范
  7. Pycharm小技巧--使用正则进行查找和批量替换
  8. jvm调优-从eclipse开始
  9. GGS-DDU HDU - 4966
  10. MySQL匹配指定字符串的查询
  11. 微信小程序之wx.request:fail错误,真机预览请求无效问题解决,安卓,ios网络预览异常
  12. Linux 的虚拟文件系统(强烈推荐)
  13. ES6学习笔记(二):引用数据类型
  14. ERP渠道文档管理(二十四)
  15. python-day9-数据类型总结
  16. LeetCode 318. Maximum Product of Word Lengths (状态压缩)
  17. Linux C single linked for any data type
  18. js中为什么非要alert一下下一步才会执行
  19. django视图函数中 应用装饰器
  20. ballerina 学习四 如何进行项目结构规划

热门文章

  1. magic packet 远程唤醒需填写 IP broadcast address
  2. 出现异常时直接把e输出比输出e.getMessage()好得多
  3. NHibernate之旅(7):初探NHibernate中的并发控制
  4. docker 搭建linux samba
  5. ISC DHCP: Enterprise grade solution for configuration needs
  6. 常用DOS下MSC指令
  7. HBase协处理器同步二级索引到Solr
  8. spark mongo 性能优化
  9. jquery.validate ajax验证
  10. VC实现趋势图绘制