scrapy 防止在ipython shell中显示调试日志信息

9rygscc1  于 2022-11-09  发布在  Python
关注(0)|答案(7)|浏览(142)

我在virtualenv中使用了scrapy shell。IPython安装在virtualenv中。当我使用

scrapy shell 'https://example.com'

并按Tab键以获得自动完成建议,它会显示大量调试信息。如何禁用此功能?

In [1]: from scra2018-03-23 10:05:45 [parso.python.diff] DEBUG: diff parser start
2018-03-23 10:05:45 [parso.python.diff] DEBUG: diff parser calculated
2018-03-23 10:05:45 [parso.python.diff] DEBUG: diff: line_lengths old: 1, new: 1
2018-03-23 10:05:45 [parso.python.diff] DEBUG: diff replace old[1:1] new[1:1]
2018-03-23 10:05:45 [parso.python.diff] DEBUG: parse_part from 1 to 1 (to 0 in part parser)
2018-03-23 10:05:45 [parso.python.diff] DEBUG: diff parser end

vmdwslir

vmdwslir1#

https://github.com/ipython/ipython/issues/10946似乎在此处报告了错误。
如果您需要在ipython中调试日志记录,请尝试logging.getLogger('parso.cache').disabled=True logging.getLogger('parso.cache.pickle').disabled=True
并继续等待Parso更新

rsl1atfo

rsl1atfo2#

尝试执行此操作以将日志记录级别设置为WARNING

import logging

logging.getLogger().setLevel(logging.WARNING);

任何INFODEBUG级别的日志消息都不会再出现。您也可以将日志级别设置为logging.ERROR。这样,WARNING消息也不会出现。
祝你好运!

rbpvctlc

rbpvctlc3#

您可以使用-L命令行选项将日志级别更改为INFO

scrapy shell -L INFO https://example.com
bjg7j2ky

bjg7j2ky4#

您可以在www.example.com文件中设置日志级别settings.py,如文档
LOG_LEVEL = 'INFO'
这将隐藏DEBUG级别的消息。

mspsb9vt

mspsb9vt5#

在这个答案的基础上,将它添加到你的pythonstartup $PYTHONSTARTUP中

try:
    _ = __IPYTHON__ 
    import IPython
    ip=IPython.get_ipython()
    c = ip.__dict__['Completer'] 
    import logging
    logging.getLogger('parso.cache').disabled=True
    logging.getLogger('parso.cache.pickle').disabled=True
    print(">> debug msg from $HOME/.pythonrc.py <<")
except NameError:
    pass # no ipython
7lrncoxx

7lrncoxx6#

在shell中执行以下代码:

__import__("logging").getLogger("parso.python.diff").setLevel("INFO")
__import__("logging").getLogger("parso.cache").setLevel("INFO")
__import__("logging").getLogger("asyncio").setLevel("INFO")
mv1qrgav

mv1qrgav7#

我在这方面承了很久,没有找到一个理想的解决办法,等我卸载了parso模块之后,一切都好了!

pip uninstall parso

相关问题