zoukankan      html  css  js  c++  java
  • python中的logging模块使用

    #日志类
    import os
    import logging

    current_path = os.path.dirname(__file__)
    log_path = os.path.join(current_path, '../log/testpython.log')

    class logUtil:
    def __init__(self,logfile_path=log_path):
    self.logfile_path=log_path
    self.logger = logging.getLogger('log_util')
    self.logger.setLevel(level=logging.INFO)
    file_log = logging.FileHandler(log_path) # 闯将一个文件日志对象
    formatter = logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s')
    file_log.setFormatter(formatter)
    self.logger.addHandler(file_log)


    def info(self,message):
    self.logger.info(message)

    def error(self,errmessage):
    self.logger.error(errmessage)

    log_info=logUtil(log_path)

    if __name__ == '__main__':
    log=logUtil(log_path)
    log.error('系统异常')
    log.info('登录成功')
  • 相关阅读:
    第二阶段Sprint2
    第二阶段Sprint1
    Sprint10
    Sprint9
    Sprint8
    Sprint7
    第二阶段个人工作总结(2)
    第二阶段个人工作总结(1)
    查找三个“水王”
    构建之法阅读笔记03
  • 原文地址:https://www.cnblogs.com/tingting-yang/p/13410795.html
Copyright © 2011-2022 走看看