pytohon 日志处理 logging模块
来源:互联网 发布:天音复制软件 编辑:程序博客网 时间:2024/06/13 09:31
日志处理
# -*- coding:utf-8 -*-import loggingimport getpassimport datetimeclass MyLog(object): def __init__(self): self.user = getpass.getuser() self.logger = logging.getLogger(self.user) self.logger.setLevel(logging.DEBUG) #日志文件名称 self.logFile = datetime.datetime.now().strftime("%Y-%m-%d")+ '.log' self.formatter = logging.Formatter('%(asctime)-12s %(levelname)-8s %(name)-10s %(message)-12s\r\n') #日志输出到屏幕和日志文件 self.logHand = logging.FileHandler(self.logFile,encoding='utf8') self.logHand.setFormatter(self.formatter) self.logHand.setLevel(logging.DEBUG) self.logHandSt = logging.StreamHandler() self.logHandSt.setFormatter(self.formatter) self.logHandSt.setLevel(logging.DEBUG) self.logger.addHandler(self.logHand) self.logger.addHandler(self.logHandSt) # 日志五个级别对应一下五个方法 def debug(self,msg): self.logger.debug(msg) def info(self,msg): self.logger.info(msg) def warn(self,msg): self.logger.warn(msg) def error(self,msg): self.logger.error(msg) def critical(self,msg): self.logger.critical(msg)if __name__ == "__main__": log = MyLog() log.debug("这是debug日志") log.error("这是error日志") log.warn("这是warn日志")
阅读全文
0 0
- pytohon 日志处理 logging模块
- Python日志处理之logging模块
- Python日志模块-logging
- Python日志模块logging
- <>logging 日志模块
- Python 日志(logging)模块
- Python:logging日志模块
- python日志模块----logging
- python 日志模块 logging
- python(logging )日志模块
- python logging日志模块
- Python 日志logging模块
- python logging日志模块
- python日志模块---logging
- python 日志模块logging
- Python--日志模块Logging
- python logging日志模块
- Python logging 日志模块
- 关于建站、服务器、云虚拟主机你想知道的都在这里!
- 一步步将vim改造成C/C++开发环境(IDE)
- web项目的启动时文件加载顺序
- java中的try-catch-finally执行顺序你真的弄清楚了吗?
- go
- pytohon 日志处理 logging模块
- 压力测试工具 wrk
- angularJs中ng-cloak指令
- 以太网帧结构以及CRC校验
- spark spark_deploy_mode配置详解
- 接口入参保护
- ajax返回json串
- 计算机为什么使用补码?(讲的很详细)
- 文本三剑客之awk