热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

Python日志和Pydev调试器?

如何解决《Python日志和Pydev调试器?》经验,为你挑选了2个好方法。

编辑:

使用Liclipse 1.2.1代替1.3.0或1.4.0工作正常.Changelog表示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]

谢谢



1> nmz787..:

现在有一个相对模糊的(因为它们不包括用于良好搜索索引的网页中的OP错误字符串)在PyCharm中实现的修复:https://www.jetbrains.com/pycharm/help/python-debugger . HTML

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

然后取消选中'PyQt compatible'



2> 小智..:

与PyCharm相同的问题.可能的解决方法 - 在pycharm/helpers/pydev/pydevd.py中注释掉pydev_monkey_qt.patch_qt()行,对于Eclipse它应该位于其他地方


推荐阅读
author-avatar
campionezhao
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有