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('登录成功')
  • 相关阅读:
    资源限制
    垃圾收集器
    GC日志
    happens-before
    maven相互依赖导致无法编译成功
    LVM-逻辑卷常用命令和示意图
    取消RAID5
    扩展RAID5的容量
    模拟RAID5损坏
    创建RAID5
  • 原文地址:https://www.cnblogs.com/tingting-yang/p/13410795.html
Copyright © 2011-2022 走看看