Turning off logging in Selenium (from Python)

前端 未结 4 825
被撕碎了的回忆
被撕碎了的回忆 2020-11-27 19:16

I\'ve recently inherited some Selenium Webdriver code, written in Python 2.7. It is logging copious amounts of data to /tmp on Ubuntu - so much that it is becoming a problem

4条回答
  •  暖寄归人
    2020-11-27 19:47

    The answer from alecxe worked for me. There were still some debug messages in the log however, originating from urllib3. It is imported by selenium, and not affected by the solution above. Here is what I used, for what it's worth:

    # Set the threshold for selenium to WARNING
    from selenium.webdriver.remote.remote_connection import LOGGER as seleniumLogger
    seleniumLogger.setLevel(logging.WARNING)
    # Set the threshold for urllib3 to WARNING
    from urllib3.connectionpool import log as urllibLogger
    urllibLogger.setLevel(logging.WARNING)
    

    If someone knows of more pythonic way to achieve the same - I'll be glad to hear it.

提交回复
热议问题