First of all, wonderful post.
I'm working on a Flask application right now: first time with Python and I was looking for useful information about how to write logs the right way when I saw this post — awesome!
Anyway, I tried to copy & paste the code but it looks like the logger object doesn't care about the format you passed to logging.basicConfig if you are using the FileHandler and you've to explicitly call .setFormatter to make it know.
log_formatter = logging.Formatter('%(asctime)s - %(levelname)s --: %(message)s')
file_handler = logging.FileHandler('logfile')
Might wanna look at the docs at the app specific logger flask.pocoo.org/docs/1.0/logging/ it also shows how to do some useful stuff like access library loggers and such
Thank you for the useful post. Just a quick correction.
Running the sample code under Logging to a File, the logger is created with a default level of WARNING, so the INFO log record is actually not written to the log file. To include it in the log file, set the logger level to INFO as well:
logger = logging.getLogger(__name__)
Thanks for catching that, I'll leave a note in the article!
really a nice write :D would have helped me a lot if I found this a few weeks back :p
We're a place where coders share, stay up-to-date and grow their careers.
We strive for transparency and don't collect excess data.