Skip to content

[πŸ› Bug]: Python logging not working correctlyΒ #15359

@cgoldberg

Description

@cgoldberg

What happened?

I'm not sure if this is a bug or a documentation issue, but I am unable to get any logging working from the Python bindings using the logging instructions from the official docs.

According to the Python examples in the docs, DEBUG level logging to the console can be enabled with:

logger = logging.getLogger('selenium')
logger.setLevel(logging.DEBUG)

The following code should open Chrome and load a url, while displaying DEBUG level logs to the console:

import logging
from selenium import webdriver

logger = logging.getLogger('selenium')
logger.setLevel(logging.DEBUG)

with webdriver.Chrome() as driver:
    driver.get('https://example.com')

However, nothing is displayed to the console.

I can enable DEBUG logging globally for all modules, with:

logging.basicConfig(level=logging.DEBUG)

This works... The following code opens Chrome and loads a url, while displaying DEBUG level logs to the console:

import logging
from selenium import webdriver

logging.basicConfig(level=logging.DEBUG)

with webdriver.Chrome() as driver:
    driver.get('https://example.com')

I get the full set of logs doing that... but this isn't ideal since it enables logging for every module and doesn't allow more fine-grained adjustments.

So why does the first example not display any logs? Either there is something wrong with logging in selenium, or the docs are not correct (or I have somehow misinterpreted them).

How can we reproduce the issue?

See description above.

Relevant log output

N/A

Operating System

All OS

Selenium version

Python Selenium 4.29.0

What are the browser(s) and version(s) where you see this issue?

All browsers

What are the browser driver(s) and version(s) where you see this issue?

All drivers

Are you using Selenium Grid?

No

Metadata

Metadata

Assignees

No one assigned

    Labels

    B-docsAPI Docs; see other repo for website documentationC-pyPython BindingsI-defectSomething is not working as intended

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions