【问题标题】:Prevent showing debugging log info inside ipython shell防止在 ipython shell 中显示调试日志信息
【发布时间】:2018-03-23 04:47:54
【问题描述】:

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

 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

【问题讨论】:

    标签: python python-3.x scrapy ipython


    【解决方案1】:

    https://github.com/ipython/ipython/issues/10946 好像这里报告了错误。

    如果您需要在 ipython 中调试日志记录,请尝试 logging.getLogger('parso.cache').disabled=True logging.getLogger('parso.cache.pickle').disabled=True

    等待解析更新

    【讨论】:

    • 是的,这个问题和我的一模一样。
    • 有没有办法在你启动 shell 时自动运行它?
    • 只需将其添加到 ~/.ipython/profile_default/startup/00-first.py
    • 对我来说有效的是logging.getLogger('parso').setLevel(logging.WARNING)
    【解决方案2】:

    尝试这样做将日志记录级别设置为WARNING

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

    任何级别为INFODEBUG 的日志消息都不应再出现。您还可以将日志级别设置为logging.ERROR。那么WARNING 消息也不会出现。

    祝你好运!

    【讨论】:

    • 它解决了我的问题。我不是每次都这样做,而是将其写入我的settings.py
    • 酷,很高兴我能帮上忙!祝你好运:)
    【解决方案3】:

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

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

    【讨论】:

      【解决方案4】:

      您可以在settings.py文件as described in docs中设置日志级别

      LOG_LEVEL = 'INFO'

      这将从scrapy隐藏DEBUG级别的消息。

      【讨论】:

        【解决方案5】:

        在答案的基础上将此添加到您的 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
        

        【讨论】:

          【解决方案6】:

          在shell中执行这段代码:

          __import__("logging").getLogger("parso.python.diff").disabled=True
          

          【讨论】:

            【解决方案7】:

            忍了很久,没有找到理想的解决方案,卸载了parso模块后,一切正常!

            pip uninstall parso
            

            【讨论】:

              猜你喜欢
              • 1970-01-01
              • 1970-01-01
              • 1970-01-01
              • 1970-01-01
              • 2019-06-03
              • 1970-01-01
              • 1970-01-01
              • 1970-01-01
              • 2019-06-05
              相关资源
              最近更新 更多