How to auto generate log file in VS Code after deleting it using python?

Viewed 21

I have this code to generate a log file in VS Code.

import logging

logging.basicConfig(filename='example.log', encoding='utf-8', level=logging.DEBUG)
logging.debug('This message should go to the log file')
logging.info('So should this')
logging.warning('And this, too')
logging.error('And non-ASCII stuff, too, like Øresund and Malmö')

Then, I deleted the example.log file thinking that it will auto-generate every time I run the code. But now, I am unable to generate a log file. So, I was wondering how can we generate a log with this code. What is the issue here?

1 Answers

this should work

logging.basicConfig( handlers=[ logging.FileHandler('logs.log') ], level=logging.INFO)
Related