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")

 

 

posted @ 2021-04-18 16:19  远哥说  阅读(1675)  评论(0)    收藏  举报