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

How to enable logging module on wdm version 3.8.3? #424

Closed
faalbers opened this issue Aug 2, 2022 · 7 comments
Closed

How to enable logging module on wdm version 3.8.3? #424

faalbers opened this issue Aug 2, 2022 · 7 comments
Assignees
Labels

Comments

@faalbers
Copy link

faalbers commented Aug 2, 2022

I'm using logging to log into a file.

When I use:
from webdriver_manager.chrome import ChromeDriverManager

logging does not work correctly anymore. It prints in the console instead of in the log file

@mouadessalim
Copy link

Hey @faalbers we may need more informations to help you. Like screenshot and your environment.

@skuenzli
Copy link

skuenzli commented Oct 5, 2022

Hi @mouadessalim - I may be experiencing the same issue.

I've been using webdriver-manager==3.8.0, upgraded to 3.8.3 and lost all logging. Even after explicitly adding a handler for stdout.

My working Python 3.8.5 virtual environment has:

(venv) skuenzli$ pip freeze
beautifulsoup4==4.9.3
certifi==2020.12.5
chardet==4.0.0
idna==2.10
pybrowsers==0.5.0
python-dotenv==0.20.0
requests==2.25.1
selenium==3.141.0
soupsieve==2.2
tqdm==4.64.1
urllib3==1.26.3
webdriver-manager==3.8.0

My logging output is eaten for webdriver-manager 3.8.1 - 3.8.3.

However, print() still displays to stdout.

HTH

@mouadessalim
Copy link

try to add in your code :

webdriver_manager/README.md

Lines 216 to 224 in dd39e87

### `WDM_LOG`
Turn off webdriver-manager logs use:
```python
import logging
import os
os.environ['WDM_LOG'] = str(logging.NOTSET)
```

@skuenzli
Copy link

skuenzli commented Oct 6, 2022

I tried turning off the WDM logs in my code with

imports ...

os.environ['WDM_LOG'] = str(logging.NOTSET)

I also tried executing with a WDM_LOG=0 env var.

All logs suppressed except:

[WDM] - Downloading: 100%| ...

I know we're debugging here, but I do want the WDM logger output. It's very useful in my work.

@mouadessalim
Copy link

look at #434. I've already asked the same question.

@skuenzli
Copy link

skuenzli commented Oct 6, 2022

I figured out my issue.

Short Answer: (Completely) Follow the canonical StackOverflow answer for configuring python logging to stdout

Long Answer:
I was unintentionally relying on webdriver_manager 3.8.0's logging configs for stdout.

And it seems like the webdriver_manager logging config changed significantly in 3.8.1. I haven't tracked down the commit, but I suspect it no longer adds a stdout handler to the root logger. This is fine and probably preferable for most applications.

When I configured my own handler for stdout, I forgot the final step of adding the stdout handler to the root logger.

My complete, working config for logging to stdout:

root_logger = logging.getLogger()
LOG_LEVEL = os.environ.get('LOG_LEVEL', 'INFO').upper()
root_logger.setLevel(level=LOG_LEVEL)

stdout_handler = logging.StreamHandler(sys.stdout)
stdout_handler.setLevel(logging.INFO)
formatter = logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s')
stdout_handler.setFormatter(formatter)
root_logger.addHandler(stdout_handler)  # forgot this 🥲 

logger = logging.getLogger(__name__)

@aleksandr-kotlyar
Copy link
Collaborator

Seems problem has been solved.
As i see @skuenzli you could just set log level to info to make it work.

Also 3.8.5 webdriver manager available and it also works fine if set log level and enable log cli in pytest.

@aleksandr-kotlyar aleksandr-kotlyar changed the title logging module does not work correctly with ChromeDriveManager How to enable logging module on 3.8.3 (after 3.8.0) Feb 14, 2023
@aleksandr-kotlyar aleksandr-kotlyar changed the title How to enable logging module on 3.8.3 (after 3.8.0) How to enable logging module on wdm version 3.8.3? Feb 14, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants