Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prevent log-informations? #277

Closed
Rapid1898-code opened this issue Nov 19, 2021 · 10 comments · Fixed by #343
Closed

Prevent log-informations? #277

Rapid1898-code opened this issue Nov 19, 2021 · 10 comments · Fixed by #343
Assignees

Comments

@Rapid1898-code
Copy link

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
Copy link

baca90 commented Nov 20, 2021

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
Copy link
Author

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
Copy link

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
Copy link
Author

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
Copy link

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
Copy link

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
Copy link

this is also in #287

@dwightmulcahy
Copy link

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
Copy link

dwightmulcahy commented Feb 11, 2022

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 added a commit to aleksandr-kotlyar/webdriver_manager that referenced this issue Mar 9, 2022
aleksandr-kotlyar added a commit to aleksandr-kotlyar/webdriver_manager that referenced this issue Mar 10, 2022
aleksandr-kotlyar added a commit to aleksandr-kotlyar/webdriver_manager that referenced this issue Mar 10, 2022
aleksandr-kotlyar added a commit to aleksandr-kotlyar/webdriver_manager that referenced this issue Mar 10, 2022
aleksandr-kotlyar added a commit that referenced this issue Mar 10, 2022
* gh #277 os.environ['WDM_LOG'] == '0' disables logs

* gh #277 Add suite with WDM_LOG = "0"; Optimize test matrix.
@aleksandr-kotlyar
Copy link
Collaborator

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

webdriver_manager/README.md

Lines 207 to 209 in 1281af3

import os
os.environ['WDM_LOG'] = '0'

This should work and would not affect your project loggers.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
5 participants