Skip to content

[Bug/Enhancement] logger.catch(level=...) incorrectly rendered when using standard logging library levels #1054

@jmy12k3

Description

@jmy12k3

When using logger.catch with error codes from the standard logging library, the log level will be rendered incorrectly as below:

from logging import CRITICAL

from loguru import logger


@logger.catch(level=CRITICAL)
def error():
    raise Exception


error()
2024-01-01 20:38:27.032 | Level 50 | __main__:<module>:11 - An error has been caught in function '<module>', process 'MainProcess' (80296), thread 'MainThread' (7921619712):
Traceback (most recent call last):

> File "/Users/jimmy/Desktop/dev/Enigma/test.py", line 11, in <module>
    error()
    └ <function error at 0x103c52d40>

  File "/Users/jimmy/Desktop/dev/Enigma/test.py", line 8, in error
    raise Exception

Exception

This behaviour however is fixed when passing a string in logger.catch, as the code snippets below:

from loguru import logger


@logger.catch(level="CRITICAL")
def error():
    raise Exception


error()
2024-01-01 20:39:46.068 | CRITICAL | __main__:<module>:11 - An error has been caught in function '<module>', process 'MainProcess' (80376), thread 'MainThread' (7921619712):
Traceback (most recent call last):

> File "/Users/jimmy/Desktop/dev/Enigma/test.py", line 11, in <module>
    error()
    └ <function error at 0x1050f6d40>

  File "/Users/jimmy/Desktop/dev/Enigma/test.py", line 8, in error
    raise Exception

Exception

Is this an intended feature or a bug? Many thanks for the answer.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions