i want to print all the messages in logfile

Viewed 85

I have created a log file and only error and critical messages are appearing as output I have to display all the messages

import logging
        Log_format="%(levelname)s %(asctime)s - %(message)s"
        # create and configure logger
        logging.basicConfig(filename="logfile.log",
                            filemode='w',
                            format=Log_format,
                            level=logging.ERROR)
        logger=logging.getLogger()
        # test messages
        logger.error("first logging message")
        logger.debug("Harmless debug Message")
        logger.info("Just an information")
        logger.warning("Its a Warning")
        logger.error("Did you try to divide by zero")
        logger.critical("Internet is down")
2 Answers

You have to set the threshold of logger to DEBUG..

logger.setLevel(logging.DEBUG)

In logging.basicConfig you have requested

level=logging.ERROR

thus only ERROR and more severe will be saved (see logging docs for hierarchy of levels), if you wish to have all set level to logging.DEBUG (least severe of all you have used) or logging.NOTSET

Related