Skip to content Skip to main navigation Skip to footer

python中如何编写日志封装类

python中编写日志封装类是如何来实现的呢?下面的内容将会通过具体的实例来演示python中编写日志封装类的实现方法及相关技巧:

本文实例讲述了python实现写日志封装类。分享给大家供大家参考。具体如下:

# encoding:utf-8
import sys
import logging
import time
def writeLog(message):
  logger=logging.getLogger()
  filename = time.strftime('%Y-%m-%d',time.localtime(time.time()))
  handler=logging.FileHandler("./log/"+filename+"error")
  logger.addHandler(handler)
  logger.setLevel(logging.NOTSET)
  logger.info(message)
if __name__ == '__main__':
  writeLog("hello")
 

将这段代码保存为 TLog,调用的时候先import TLog,然后TLog.writelog(“jb51.net”)即可


python中编写日志封装类就是这样,欢迎大家参考。。。。

0 Comments

There are no comments yet

Leave a comment

Your email address will not be published.