Python 日志记录和 Pydev 调试器?

标签 python debugging logging configuration pycharm

编辑:

使用 Liclipse 1.2.1 而不是 1.3.0 或 1.4.0 工作正常。变更日志表明 Pydev 3.9.1 和 Eclipse 4.4.1 都针对 1.3.0 进行了更新。似乎中断了日志记录调试。


将 Liclipse 和 Pydev 调试器(和 CPython)与以下代码示例一起使用,得到该错误:

 logging.config.dictConfig(config)
 File "C:\Python27\lib\logging\config.py", line 794, in dictConfig
   dictConfigClass(config).configure()
 File "C:\Python27\lib\logging\config.py", line 576, in configure
   '%r: %s' % (name, e))
 ValueError: Unable to configure handler 'console': 'DictConfigurator' object has no attribute 'startswith'

不调试就没有问题,是不是logging模块需要运行环境,才会在上面运行?

这里是使用的代码示例:

import logging.config
import yaml

def setup_logging():    
    default_path = 'logger.conf' 
    default_level = logging.DEBUG

    if os.path.exists(default_path):
        with open(default_path, 'rt') as f:
            config = yaml.load(f.read())
        logging.config.dictConfig(config)
    else:
        logging.basicConfig(level=default_level)

这是我的 logger.conf :

version: 1
disable_existing_loggers: False

formatters:
    simple:
        format: "%(asctime)s - %(name)s - %(levelname)s - %(message)s"
    lineInfo:
        format: "%(asctime)s - Line: %(lineno)d - %(name)s - %(levelname)s - %(message)s"

handlers:
    console:
        class: logging.StreamHandler
        level: DEBUG
        formatter: lineInfo
        stream: ext://sys.stdout
    debug_file_handler:
        class: logging.handlers.RotatingFileHandler
        level: DEBUG            
        formatter: lineInfo
        filename: logs/debug.log
        maxBytes: 10485760 # 10MB
        backupCount: 10
        encoding: utf8
    info_file_handler:
        class: logging.handlers.RotatingFileHandler
        level: INFO            
        formatter: simple
        filename: logs/info.log
        maxBytes: 10485760 # 10MB
        backupCount: 10
        encoding: utf8
    error_file_handler:
        class: logging.handlers.RotatingFileHandler
        level: ERROR            
        formatter: simple
        filename: logs/errors.log
        maxBytes: 10485760 # 10MB
        backupCount: 10
        encoding: utf8
root:
    level: DEBUG
    handlers: [console, info_file_handler, error_file_handler, debug_file_handler]

谢谢

最佳答案

现在在 PyCharm 中为此实现了一个相对晦涩的修复(因为他们没有在其网页中包含 OP 的错误字符串以进行良好的搜索索引): https://www.jetbrains.com/pycharm/help/python-debugger.html

在 PyCharm 中,转到: 文件 |设置 |构建、执行、部署 | Python 调试器

然后取消选中“PyQt 兼容”

关于Python 日志记录和 Pydev 调试器?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28806403/

相关文章:

python - 剪刀石头布

python - 用多个变量填充网格

javascript - 如何记录对 JavaScript 对象的成员函数的每次调用?

python - 一个更好的 python 属性装饰器

java - 通过 MyBatis 记录 SQL 查询时间

ios - 安装ios应用程序时如何获取LOG?

python - 从文本文件中提取特定数据

python - 从 Python 3 : Access denied for user 访问 MySQL

javascript - 覆盖 console.log();用于生产

logging - 我无法再从 Google Apps 脚本中找到日志(由 Logger 创建)