0
0
Flaskframework~10 mins

Logging in production in Flask - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to import the logging module in a Flask app.

Flask
import [1]
Drag options to blanks, or click blank then click option'
Aos
Blogging
Csys
Djson
Attempts:
3 left
💡 Hint
Common Mistakes
Importing unrelated modules like os or sys.
Forgetting to import logging before using it.
2fill in blank
medium

Complete the code to set the logging level to WARNING in a Flask app.

Flask
app.logger.setLevel(logging.[1])
Drag options to blanks, or click blank then click option'
AERROR
BDEBUG
CWARNING
DINFO
Attempts:
3 left
💡 Hint
Common Mistakes
Using DEBUG level which logs too much information.
Using INFO level which logs less than DEBUG but more than WARNING.
3fill in blank
hard

Fix the error in the code to log an error message in Flask.

Flask
app.logger.[1]("An error occurred")
Drag options to blanks, or click blank then click option'
Aerror
Blog
Cwarn
Dprint
Attempts:
3 left
💡 Hint
Common Mistakes
Using warn instead of error.
Trying to use print which does not log properly.
4fill in blank
hard

Fill both blanks to configure a file handler for logging in Flask.

Flask
file_handler = logging.[1]('app.log')
file_handler.setLevel(logging.[2])
Drag options to blanks, or click blank then click option'
AFileHandler
BStreamHandler
CWARNING
DDEBUG
Attempts:
3 left
💡 Hint
Common Mistakes
Using StreamHandler which logs to console, not file.
Setting level to DEBUG which logs too much.
5fill in blank
hard

Fill all three blanks to add the file handler to the Flask app logger with a formatter.

Flask
formatter = logging.[1]('%(asctime)s - %(levelname)s - %(message)s')
file_handler.setFormatter([2])
app.logger.[3](file_handler)
Drag options to blanks, or click blank then click option'
AFormatter
Bformatter
CaddHandler
DremoveHandler
Attempts:
3 left
💡 Hint
Common Mistakes
Using removeHandler instead of addHandler.
Not setting a formatter on the handler.
Confusing the formatter class and instance.