Setting up basic file logging
By default, Flask will not log anything for us anywhere, except for the errors with the stack traces, which are sent to the logger (we will see more of this in the rest of the chapter). It does create a lot of stack traces while we run the application in the development mode using run.py
, but in production systems, we don’t have this luxury. Thankfully, the logging library provides a whole lot of log handlers, which can be used as per requirements. In this recipe, we will understand how the logging
library can be leveraged to ensure that effective logs are being captured from Flask applications.
Getting ready
We will start with our catalog application from the previous chapter and add some basic logging to it using FileHandler
, which logs messages to a specified file on the filesystem. We will start with a basic log format and then see how to format the log messages to be more informative.
How to do it...
Follow these steps to configure...