Reputation: 142
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")
Upvotes: 2
Views: 384
Reputation: 129
You have to set the threshold of logger
to DEBUG
..
logger.setLevel(logging.DEBUG)
Upvotes: 2
Reputation: 36560
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
Upvotes: 1