Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Logging with level number doesn't produce expected result #1011

Closed
joejoinerr opened this issue Oct 23, 2023 · 2 comments
Closed

Logging with level number doesn't produce expected result #1011

joejoinerr opened this issue Oct 23, 2023 · 2 comments
Labels
question Further information is requested

Comments

@joejoinerr
Copy link

When using the Logger.log() method with a level number, the log message is generated with Level [number] rather than the name of the severity level. This is different to the behaviour of the builtin logging library and not what I would expect from looking at the implementation.

image

from loguru import logger

logger.log(10, 'Test message')
logger.log('DEBUG', 'Test message')
print(logger.level('DEBUG'))

I would expect the output of both log messages to show "DEBUG" as the log severity.

Python 3.10.2
Loguru 0.7.0

@Delgan
Copy link
Owner

Delgan commented Oct 23, 2023

Hi.

This is actually by design. When using an integer, the level will be treated as anonymous. This is because there is no way to uniquely identify a level by a integer, since two levels with different names can share the same severity.

See also #599.

@joejoinerr
Copy link
Author

Ah that makes a lot of sense. My issue was using this with the tenacity library, specifically the tenacity.before_sleep_log function. But I realised I can just provide the level name instead and it works just fine.

Apologies for the duplicate question. Thanks for your help, and for all your work on Loguru :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants