In a python script I am writing, I am trying to log events using the logging module. I have the following code to configure my logger:
ERROR_FORMAT = \"%(levelna
For anyone here that wants a super-simple answer: just set the level you want displayed. At the top of all my scripts I just put:
import logging
logging.basicConfig(level = logging.INFO)
Then to display anything at or above that level:
logging.info("Hi you just set your fleeb to level plumbus")
It is a hierarchical set of five levels so that logs will display at the level you set, or higher. So if you want to display an error you could use logging.error("The plumbus is broken")
.
The levels, in increasing order of severity, are DEBUG
, INFO
, WARNING
, ERROR
, and CRITICAL
. The default setting is WARNING
.
This is a good article containing this information expressed better than my answer:
https://www.digitalocean.com/community/tutorials/how-to-use-logging-in-python-3