Gopi
Gopi

Reputation: 13

Python FileHandler not writing logger.info messages

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.

Upvotes: 1

Views: 52

Answers (1)

Sven Eberth
Sven Eberth

Reputation: 3115

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

log.setLevel(logging.DEBUG)

Upvotes: 1

Related Questions