zoukankan      html  css  js  c++  java
  • python 日志的配置,python对日志封装成类,日志的调用

    # python 日志的配置,python对日志封装成类,日志的调用
    
    import logging
    
    # 使用logging模块:
    class CLog:
        # ----------------------------------------------------------------------------
        def __init__(self):
            #日志文件的存放路径,根据自己的需要去修改
            LOG_FILE_PATH = 'C:\log\wlb\crawler\cic.log'
            self.logger = logging.getLogger()
            fileHandler = logging.FileHandler(LOG_FILE_PATH)
            #日志的输出格式
            fmt = '
    ' + '%(asctime)s - %(filename)s:%(lineno)s  - %(message)s'
            formatter = logging.Formatter(fmt)  # 实例化formatter
            fileHandler.setFormatter(formatter)
            self.logger.addHandler(fileHandler)
            self.logger.setLevel(logging.NOTSET)
    
        def DebugMessage(self, msg):
            self.logger.debug(msg)
            pass
    
    # 调用日志模块
    oCLog = CLog()
    
    a = "aa"
    b = "bb"
    c = "cc"
    d = "dd"
    logging.info("code=%s ,status=%s ,seqNo=%s;dddddddddd,ll=%s" % (a, b, c, d))
    

      

    日志的输出结果:

  • 相关阅读:
    UVA10891
    UVA10453
    UVA 10201
    UVA10154
    UVA11137
    UVA10617
    UVA10271
    UVA10739
    UVA10306
    节流防抖
  • 原文地址:https://www.cnblogs.com/xuchunlin/p/6991496.html
Copyright © 2011-2022 走看看