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 = '\n' + '%(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))

  

日志的輸出結果:

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM