Skip to content

Logging with level as integer does not map to expected log level name #1411

@RafaelWO

Description

@RafaelWO

Consider the following example:

import logging

from loguru import logger

logger.debug("Debug with `logger.debug()`")
logger.log(logging.DEBUG, "Debug with `logger.log(logging.DEBUG)`")
logger.log("DEBUG", "Debug with `logger.log('DEBUG')`")

If I run this with loguru==0.7.3, I get the following output:

2025-10-30 09:34:32.031 | DEBUG    | __main__:<module>:5 - Debug with `logger.debug()`
2025-10-30 09:34:32.031 | Level 10 | __main__:<module>:6 - Debug with `logger.log(logging.DEBUG)`
2025-10-30 09:34:32.031 | DEBUG    | __main__:<module>:7 - Debug with `logger.log('DEBUG')`

But I expected:

2025-10-30 09:34:32.031 | DEBUG    | __main__:<module>:5 - Debug with `logger.debug()`
2025-10-30 09:34:32.031 | DEBUG    | __main__:<module>:6 - Debug with `logger.log(logging.DEBUG)`
2025-10-30 09:34:32.031 | DEBUG    | __main__:<module>:7 - Debug with `logger.log('DEBUG')`

Since the logger.log() method is annotated to accept int | string, I would have expected the level name to be DEBUG if the level number 10 for debug is supplied.

Is that expected behaviour?

I am happy to provide a fix via a PR for this 🙂

Metadata

Metadata

Assignees

No one assigned

    Labels

    documentationImprovements or additions to documentationquestionFurther information is requested

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions