Reputation: 13
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
Reputation: 3115
You need to set the level of your logger as well.
log.setLevel(logging.DEBUG)
Upvotes: 1