Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

logging.info doesn't show up on console but warn and error do

People also ask

How do you show logging information in Python?

Python Logging – INFO Level To log an INFO line using Python Logging, Check if the logger has atleast a logging level of INFO. Use logging.info() method, with the message passed as argument, to print the INFO line to the console or log file.

How do I enable logging in Python?

You can configure logging as shown above using the module and class functions or by creating a config file or a dictionary and loading it using fileConfig() or dictConfig() respectively. These are useful in case you want to change your logging configuration in a running application.

How do I log into the console in Python?

Use the logging Module to Print the Log Message to Console in Python. To use logging and set up the basic configuration, we use logging. basicConfig() . Then instead of print() , we call logging.

Where does logger info write to Python?

We can also use the logging. FileHandler() function to write logs to a file in Python. This function takes the file path where we want to write our logs. We can then use the addHandler() function to add this handler to our logger object.


The root logger always defaults to WARNING level. Try calling

logging.getLogger().setLevel(logging.INFO)

and you should be fine.


Like @ztyx said that default logger level is WARNING. You have to set it to a lower level

You can do it by using logging.basicConfig and setting logger level:

logging.basicConfig(level=logging.DEBUG)

The above solutions didn't work for me, but the code here did:

# set up logging to file
logging.basicConfig(level=logging.DEBUG,
                    format='%(asctime)s %(name)-12s %(levelname)-8s %(message)s',
                    datefmt='%m-%d %H:%M',
                    filename='/temp/myapp.log',
                    filemode='w')
# define a Handler which writes INFO messages or higher to the sys.stderr
console = logging.StreamHandler()
console.setLevel(logging.INFO)
# add the handler to the root logger
logging.getLogger('').addHandler(console)

(I omitted parts of the code for the sake of readability)


This will work

import logging

logging.basicConfig()
logger = logging.getLogger(__name__)
logger.setLevel(logging.INFO)

logger.info('its working')