Python FileHandler not writing logger.info messages

Viewed 39
Format = logging.Formatter("%(asctime)s %(message)s")
fileName = 'invokeRestApi.log'
fileMode = 'a'

log = logging.getLogger('simple_example')
fileHandler = logging.FileHandler(fileName, 'a')
fileHandler.setLevel(logging.DEBUG)
fileHandler.setFormatter(Format)

consoleHandler = logging.StreamHandler()
consoleHandler.setLevel(logging.DEBUG)
consoleHandler.setFormatter(Format)
log.addHandler(consoleHandler)
log.addHandler(fileHandler)
log.info("Hello)

When executing the code, nothing is written to the file. If I do log.error then the message is going to the file.

1 Answers

You need to set the level of your logger as well.

log.setLevel(logging.DEBUG)
Related