我想打印日志文件中的所有消息

i want to print all the messages in logfile

我创建了一个日志文件,但只有错误和关键消息作为输出出现我必须显示所有消息

import logging
        Log_format="%(levelname)s %(asctime)s - %(message)s"
        # create and configure logger
        logging.basicConfig(filename="logfile.log",
                            filemode='w',
                            format=Log_format,
                            level=logging.ERROR)
        logger=logging.getLogger()
        # test messages
        logger.error("first logging message")
        logger.debug("Harmless debug Message")
        logger.info("Just an information")
        logger.warning("Its a Warning")
        logger.error("Did you try to divide by zero")
        logger.critical("Internet is down")

logging.basicConfig你已经请求

level=logging.ERROR

因此只有 ERROR 和更严重的将被保存(请参阅 logging docs 了解级别的层次结构),如果您希望全部设置 levellogging.DEBUG(你用过的最不严重的)或logging.NOTSET

您必须将 logger 的阈值设置为 DEBUG..

logger.setLevel(logging.DEBUG)