python写日志封装类实例
时间:2020-10-10 22:23:51|栏目: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程序设计有所帮助。
上一篇:Numpy中ndim、shape、dtype、astype的用法详解
栏 目:Python代码
下一篇:Python爬虫与反爬虫大战
本文标题:python写日志封装类实例
本文地址:http://www.codeinn.net/misctech/9611.html






