python logging.basicConfig 配置


1. 創建配置文件 BasicLog.py

import logging

# 設置logging 格式
logging.basicConfig(level=logging.DEBUG, # 打印日志等級
                   format='%(filename)s %(levelname)s '
                          '[%(lineno)d] - %(threadName)s : %(message)s'
                          ' - %(asctime)s', # 日志內容
                   datefmt='[%d/%b/%Y %H:%M:%S]', # 日期格式
                   # filename='./my.log', # 日志存放位置
                   # filemode='w'
                  )


# 實例化一個logger
logger = logging.getLogger(__name__)

 

2. 其它文件中引入logger使用

from basiclog.BasicLog import logger


if __name__ == '__main__':
   logger.info("this is a log test info")
   logger.debug("this is a log test debug")
   logger.warning("this is a log test warning")

 

 


免責聲明!

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



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