2015-03-02 142 views
8

编辑:Python日志记录和Pydev调试器?

使用Liclipse 1.2.1而不是1.3.0或1.4.0工作正常。更新日志表明1.3.0的Pydev 3.9.1和Eclipse 4.4.1更新。似乎打破日志记录调试。


使用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' 

有没有调试没有问题,是记录模块需要运行环境,不仅会在...上下功夫 ?

这里是所使用的代码示例:

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] 

感谢

回答

9

同样的问题PyCharm。 可能的解决方法 - 注释掉pydev_monkey_qt.patch_qt()在pycharm /助理/ PyDev的/ pydevd.py线,为Eclipse应该位于其它地方

+0

非常感谢,PyCharm 4.0.5对我来说非常有用。 – EM0 2015-03-27 20:06:50

+0

也感谢我 - 它使用PyCharm 4.5.2。 – rettops 2015-07-06 03:21:42

+1

谢谢你也为我工作......使用'Eclipse'和'Liclipse' Eclipse Mars:/ home/ /.p2/pool/plugins Liclipse:/opt/liclipse/plugins/org.python.pydev_4.3.0。 201508181931/pysrc/pydevd.py – 2015-11-12 12:33:26

1

确保进口记录

+0

为我工作PyQt5 – 2017-03-17 09:21:58

8

有之前导入PyQt4的现在是一个相对模糊(因为它们不包括在他们的网页好的搜索索引的OP的错误字符串)修复PyCharm实施了这一点: https://www.jetbrains.com/pycharm/help/python-debugger.html

在PyCharm,请访问: 文件|设置|构建,执行,部署| Python调试器

然后取消勾选'PyQt compatible'