logging module does not work correctly with ChromeDriveManager
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
Hey @faalbers we may need more informations to help you. Like screenshot and your environment.
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
try to add in your code :
https://github.com/SergeyPirogov/webdriver_manager/blob/dd39e872f722b6f3e43d9146f25b1983231ccb80/README.md?plain=1#L216-L224
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.
look at #434. I've already asked the same question.
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__)
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.