SergeyPirogov / webdriver_manager

Apache License 2.0
2.05k stars 458 forks source link

Prevent log-informations? #277

Closed Rapid1898-code closed 2 years ago

Rapid1898-code commented 2 years ago

Hello - is there any way to prevent the program for outputting this log-informations like:

[WDM] - ====== WebDriver manager ======
[WDM] - Current google-chrome version is 96.0.4664
[WDM] - Get LATEST driver version for 96.0.4664
[WDM] - Driver [C:\Users\Polzi\.wdm\drivers\chromedriver\win32\96.0.4664.45\chromedriver.exe] found in cache

I tried it with (as it is described in the description):

import os
os.environ['WDM_PRINT_FIRST_LINE'] = 'False'  

But this is not working for me - i still get the outputs in the log.

baca90 commented 2 years ago

You should try with log_level=0 in constructor, for example webdriver.Chrome(ChromeDriverManager(log_level=0).install()) or set environment variable like below os.environ['WDM_LOG_LEVEL'] = '0'

However, I have tried both options above and still this information is in logs. I'm using Python 3.10 and pytest 6.2.5, so I guess it's a bug related to newest versions of Python and Pytest.

Rapid1898-code commented 2 years ago

With this it was working:

os.environ['WDM_LOG_LEVEL'] = '0'

But with this it wasn´t working:

srv=Service(ChromeDriverManager(log_level=0).install()) 
driver = webdriver.Chrome (service=srv, options=options)    

I am using: Python 3.9.2 Pytest i haven´t intalled when i look wit pip list

Raichuu41 commented 2 years ago

Neither way works for me unfortunately... how do I get rid of the logging? It messes up my console output on multi threading.

Rapid1898-code commented 2 years ago

Interesting - this is the full code which works for me - (the necessary command is in line 10 - with that i get no logs)

Using: Python 3.9.2 selenium 4.0.0b4 webdriver-manager 3.4.1

Are you using the same versions like me?

import time
from selenium import webdriver
from webdriver_manager.chrome import ChromeDriverManager
from selenium.webdriver.chrome.options import Options
from selenium.webdriver.chrome.service import Service
from sys import platform
import os, sys
from selenium.webdriver.support.ui import WebDriverWait

os.environ['WDM_LOG_LEVEL'] = '0'

link = "https://www.google.com/"  
options = Options()
options.add_experimental_option ('excludeSwitches', ['enable-logging'])
options.add_argument("start-maximized")
options.add_argument('window-size=1920x1080')                                 
options.add_argument('--no-sandbox')
options.add_argument('--disable-gpu')  
path = os.path.abspath (os.path.dirname (sys.argv[0]))
if platform == "win32": cd = '/chromedriver.exe'
elif platform == "linux": cd = '/chromedriver'
elif platform == "darwin": cd = '/chromedriver'
srv=Service(ChromeDriverManager().install())
driver = webdriver.Chrome (service=srv, options=options)
# driver = webdriver.Chrome (service=srv, options=options)
waitWebDriver = WebDriverWait (driver, 5)   

driver.get (link)
time.sleep(1)
Raichuu41 commented 2 years ago

I am also using exactly the same line os.environ['WDM_LOG_LEVEL'] = '0'. I have also tried it with the log_level=0 parameter on ChromeDriverManager(). I am using Python 3.9.5 (64-bit version), webdriver manager 3.4.0 and selenium 3.141.0.

I just updated the webdriver manager to 3.5.2 (latest) and selenium to 4.1.0 (latest). Now it finally works. I have tried with os.environ and with log_level, both work individually just fine now. So there seems to be a bug probably in one of the older versions of webdriver manager.

dwightmulcahy commented 2 years ago

So I am having the same problem... I have webdriver manager 3.5.2 (latest) and selenium 4.1.0 (latest) installed under Python3.8

# formatting for log messages
import logging
logging.basicConfig(
    format='%(asctime)s-%(levelname)s: %(message)s',
    datefmt='%d-%b %H:%M:%S',
    level=logging.INFO,
)
...
            os.environ['WDM_LOG_LEVEL'] = '0'
            s = Service(ChromeDriverManager(print_first_line=False, log_level=0).install())
            browser = webdriver.Chrome(service=s, options=options, service_log_path='/dev/null')

in despriration I've also tried this (which has worked for me with other "noisy" libs) logging.getLogger('webdriver_manager').setLevel(logging.ERROR)

interesting enough I am getting this as my output:

[WDM] - ====== WebDriver manager ======
29-Jan 12:42:04-INFO: ====== WebDriver manager ======
[WDM] - Trying to download new driver from https://chromedriver.storage.googleapis.com/2.26/chromedriver_mac64.zip
29-Jan 12:42:04-INFO: Trying to download new driver from https://chromedriver.storage.googleapis.com/2.26/chromedriver_mac64.zip
[WDM] - Driver has been saved in cache [/Users/dwight-personal/.wdm/drivers/chromedriver/mac64/2.26]
29-Jan 12:42:08-INFO: Driver has been saved in cache [/Users/dwight-personal/.wdm/drivers/chromedriver/mac64/2.26]

it's duplicating log messages!!! wtf?

dwightmulcahy commented 2 years ago

this is also in #287

dwightmulcahy commented 2 years ago

so finally have some time to get back to this... so I've noticed that it works when I execute the main() in a module but when I import the module into another module it outputs the ====== WebDriver manager ====== logging messages... :/

dwightmulcahy commented 2 years ago

ugh... think I figured it out.

so in the module that was calling the one that used webdriver manager it was setting this:

logging.basicConfig(format='%(asctime)s-%(levelname)s: %(message)s', datefmt='%d-%b %H:%M:%S', level=logging.INFO)

which affects all imported modules as well. I was just using logging.info(... which uses the global logger. The proper way to do this is:

logging.basicConfig(format='%(asctime)s-%(levelname)s: %(message)s', datefmt='%d-%b %H:%M:%S')

log = logging.getLogger(__name__)
log.setLevel(logging.INFO)

log.info("It works now!!!")
aleksandr-kotlyar commented 2 years ago

@Rapid1898-code @baca90 @Raichuu41 @dwightmulcahy hello! I have made a feature flag. Please check out at master branch.

https://github.com/SergeyPirogov/webdriver_manager/blob/1281af37ef4fb3fa2e30231487d56cb535216a1b/README.md#L207-L209

This should work and would not affect your project loggers.