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

标签 python logging

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

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/

相关文章:

python - 如何从字典创建 2Darray?

c# - 拥有不同配置的 NLog 记录器

Ruby:拦截 popen 系统调用并将 stdout 和 stderr 记录到同一文件

mysql - 监控 MySQL 用户的查询

python - 将列值更改为 Pandas 中的列标题

python - 如何使用 Python 计算段落中英文单词的百分比

python - 移动应用程序的 Django Rest 框架中的版本控制编程

python - 在 OpenShift 中以 HTTPS 模式配置 python flask 应用程序

java - 通过注释快速添加日志记录(例如用于 getter/setter 的 lombok) - 有可用的解决方案吗?

perl - 在 Perl 中将输出写入控制台有哪些不同的方法?