'i want to print all the messages in logfile
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")
Solution 1:[1]
You have to set the threshold of logger to DEBUG..
logger.setLevel(logging.DEBUG)
Solution 2:[2]
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
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | |
| Solution 2 | Daweo |
