0
0
Flaskframework~10 mins

Logging configuration 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'
Asys
Bflask
Cos
Dlogging
Attempts:
3 left
💡 Hint
Common Mistakes
Importing 'sys' instead of 'logging'.
Importing 'os' which is unrelated to logging.
Importing 'flask' instead of the logging module.
2fill in blank
medium

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

Flask
logging.basicConfig(level=[1])
Drag options to blanks, or click blank then click option'
Alogging.DEBUG
Blogging.WARNING
Clogging.ERROR
Dlogging.INFO
Attempts:
3 left
💡 Hint
Common Mistakes
Using logging.ERROR which only shows errors.
Using logging.WARNING which misses debug info.
Using logging.INFO which is less detailed than DEBUG.
3fill in blank
hard

Fix the error in the code to get the Flask app logger and set its level to INFO.

Flask
app_logger = app.[1]
app_logger.setLevel(logging.INFO)
Drag options to blanks, or click blank then click option'
Alog
Blogger
Clogging
Dloglevel
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'log' which does not exist on the app object.
Using 'logging' which is the module, not the attribute.
Using 'loglevel' which is not a valid attribute.
4fill in blank
hard

Fill both blanks to configure a file handler for logging to 'app.log' with level WARNING.

Flask
file_handler = logging.FileHandler('[1]')
file_handler.setLevel(logging.[2])
Drag options to blanks, or click blank then click option'
Aapp.log
Berror.log
CWARNING
DDEBUG
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'error.log' instead of 'app.log'.
Setting level to 'DEBUG' which is too verbose for this handler.
5fill in blank
hard

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

Flask
formatter = logging.Formatter('[1]')
file_handler.setFormatter(formatter)
app.logger.[2](file_handler)
Drag options to blanks, or click blank then click option'
A%(asctime)s - %(levelname)s - %(message)s
BaddHandler
Cadd_handler
DsetHandler
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'add_handler' or 'setHandler' which are incorrect method names.
Using a wrong format string that misses key log info.