编辑:
使用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]
谢谢
最佳答案
PyCharm也有同样的问题。
可能的解决方法-注释掉pycharm/helpers/pydev/pydevd.py中的pydev_monkey_qt.patch_qt()行,对于Eclipse,它应该位于其他地方
关于Python日志记录和Pydev调试器?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/28806403/