Complete the code to import the logging module in a Flask app.
import [1]
To use logging in Flask, you need to import the logging module.
Complete the code to set the logging level to WARNING in a Flask app.
app.logger.setLevel(logging.[1])Setting the logging level to WARNING means only warnings and errors will be logged.
Fix the error in the code to log an error message in Flask.
app.logger.[1]("An error occurred")
warn instead of error.print which does not log properly.The correct method to log an error message is error(). The warn() method is deprecated.
Fill both blanks to configure a file handler for logging in Flask.
file_handler = logging.[1]('app.log') file_handler.setLevel(logging.[2])
StreamHandler which logs to console, not file.FileHandler writes logs to a file. Setting level to WARNING logs warnings and above.
Fill all three blanks to add the file handler to the Flask app logger with a formatter.
formatter = logging.[1]('%(asctime)s - %(levelname)s - %(message)s') file_handler.setFormatter([2]) app.logger.[3](file_handler)
removeHandler instead of addHandler.The Formatter formats log messages. We set it on the handler, then add the handler to the app logger with addHandler.