0
0
FastAPIframework~10 mins

Logging configuration in FastAPI - 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 FastAPI.

FastAPI
import [1]
Drag options to blanks, or click blank then click option'
Asys
Bos
Cuvicorn
Dlogging
Attempts:
3 left
💡 Hint
Common Mistakes
Importing unrelated modules like os or sys.
Trying to import uvicorn instead of logging.
2fill in blank
medium

Complete the code to create a logger instance named 'app_logger'.

FastAPI
app_logger = logging.[1]('app_logger')
Drag options to blanks, or click blank then click option'
AbasicConfig
BgetLogger
CLogger
DsetLevel
Attempts:
3 left
💡 Hint
Common Mistakes
Using Logger class directly without instantiation.
Using basicConfig which is for configuration, not logger creation.
3fill in blank
hard

Fix the error in setting the logging level to INFO.

FastAPI
app_logger.setLevel(logging.[1])
Drag options to blanks, or click blank then click option'
Ainfo
BWarning
CINFO
Ddebug
Attempts:
3 left
💡 Hint
Common Mistakes
Using lowercase 'info' which causes attribute error.
Using wrong case like 'Warning' instead of 'WARNING'.
4fill in blank
hard

Fill both blanks to configure logging format and level using basicConfig.

FastAPI
logging.basicConfig(format=[1], level=logging.[2])
Drag options to blanks, or click blank then click option'
A'%(asctime)s - %(levelname)s - %(message)s'
BDEBUG
CINFO
D'%(message)s - %(levelname)s'
Attempts:
3 left
💡 Hint
Common Mistakes
Using DEBUG level when INFO is required.
Using incomplete or incorrect format strings.
5fill in blank
hard

Fill all three blanks to create a logger, set level to WARNING, and log a warning message.

FastAPI
logger = logging.[1]('my_logger')
logger.setLevel(logging.[2])
logger.[3]('This is a warning!')
Drag options to blanks, or click blank then click option'
AgetLogger
BWARNING
Cwarning
Dinfo
Attempts:
3 left
💡 Hint
Common Mistakes
Using info() method instead of warning().
Setting level to lowercase or wrong level.