Python logging not outputting anything

前端 未结 4 1039
无人及你
无人及你 2021-01-29 21:06

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         


        
4条回答
  •  无人共我
    2021-01-29 21:42

    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

提交回复
热议问题