Skip to content

Logging getLogger Documentation Incomplete #127313

@Wikilicious

Description

@Wikilicious

Documentation

The latest logging.getLogger documentation is incomplete/inaccurate.

Specifically, "If no name is specified, return the root logger.".

To more accurately reflect the code...
Change it to "If name is Falsy or 'root', return the root logger."

logging.getLogger https://github.com/python/cpython/blob/3.13/Lib/logging/__init__.py#L2128

def getLogger(name=None):
    """
    Return a logger with the specified name, creating it if necessary.

    If no name is specified, return the root logger.
    """
    if not name or isinstance(name, str) and name == root.name:
        return root
    return Logger.manager.getLogger(name)

Examples that will return root logger:

logger = logging.getLogger()
logger = logging.getLogger("")
logger = logging.getLogger("root")
logger = logging.getLogger(None)
logger = logging.getLogger(False)
logger = logging.getLogger(0)  

Linked PRs

Metadata

Metadata

Assignees

No one assigned

    Labels

    docsDocumentation in the Doc dir

    Projects

    Status

    Todo

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions