Reputation: 110257
After setting the level to info
:
import logging
logging.basicConfig(filename='example.log',level=logging.INFO)
Is there a way I can print the level
to confirm it's set to logging.INFO
? I was hoping logging.__dict__
would show it, but I can't find it from that dict.
Upvotes: 1
Views: 404
Reputation: 8954
Would this work for you?
import logging
lvl = logging.INFO
logging.basicConfig(filename='example.log',level=lvl)
print(logging.getLevelName(lvl))
>>>INFO
Upvotes: 0
Reputation: 169334
You can do it this way:
>>> logging.getLevelName(logging.getLogger().getEffectiveLevel())
'INFO'
The call to .getEffectiveLevel()
returns the numeric code of the level, and from there you get the level name via the appropriately named .getLevelName()
.
Upvotes: 2