+4 votes
in Programming Languages by (39.4k points)

I am using logging.info() to print messages on the terminal. The code is running successfully, but it does not output the message present in the logging.info() function.



does not print "hello".

How can I fix the issue?

1 Answer

+2 votes
by (281k points)
selected by
Best answer

According to the logging documentation, the default logging level is WARNING. So, if you do not change the logging level, it will not print the INFO message. There are 5 levels: DEBUG, INFO, WARNING, ERROR, CRITICAL. If you want to output detailed information, you can use DEBUG. However, DEBUG is used when the diagnosis of problems is needed.

If you want to print the INFO message, you need to set the level to INFO.

Here is an example that sets the level to INFO:

import logging
logging.basicConfig(format='%(asctime)s %(levelname)s:%(message)s', level=logging.INFO)