python写日志封装类实例

WBOY
Release: 2016-06-10 15:10:11
Original
1671 people have browsed it

本文实例讲述了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")

Copy after login

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

希望本文所述对大家的Python程序设计有所帮助。

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template