Python日志和Pydev调试器? [英] Python logging and Pydev debugger?

查看:1294
本文介绍了Python日志和Pydev调试器?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

编辑:

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

Using Liclipse 1.2.1 instead of 1.3.0 or 1.4.0 is working fine. Changelog indicate both Pydev 3.9.1 and Eclipse 4.4.1 updates for 1.3.0. Seems to break logging debug.

使用Liclipse和Pydev调试器(和CPython) :

Using Liclipse and Pydev debugger (and CPython) with the following code sample, getting that error :

 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'

没有调试没有问题,日志模块是否需要运行环境,只能工作?

There is no problem without debugging, is the logging module require run environment and will only work on it ?

下面是使用的代码示例:

Here is the code sample used :

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 :

And here is my 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相同的问题。
可能的解决方法 - 在pycharm / helpers / pydev / pydevd.py中注释掉pydev_monkey_qt.patch_qt()行,对于Eclipse,它应该位于其他地方

same problem with PyCharm. possible workaround - to comment out pydev_monkey_qt.patch_qt() line in pycharm/helpers/pydev/pydevd.py, for Eclipse it should be located somewhere else

这篇关于Python日志和Pydev调试器?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆