我创建了一个日志文件,只有错误和关键消息作为输出出现,我必须显示所有消息
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")
最佳答案
您必须将logger
的阈值设置为DEBUG
..
logger.setLevel(logging.DEBUG)
关于python - 我想打印日志文件中的所有消息,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/72110866/