Complete the code to import the logging module.
import [1]
The logging module is used to log messages in Python applications.
Complete the code to create a logger instance named 'app_logger'.
app_logger = logging.[1]('app_logger')
The getLogger function returns a logger instance with the given name.
Fix the error in the code to log an error message.
app_logger.[1]('An error occurred')
warn, info, or debug instead of error.The error method logs messages with error severity.
Fill both blanks to configure logging to show messages of level ERROR or higher with a simple format.
logging.basicConfig(level=[1], format='[2]')
Setting level=logging.ERROR ensures only error and above messages are shown. The format %(levelname)s: %(message)s shows the level and message.
Fill all three blanks to log an error with exception info inside a FastAPI exception handler.
from fastapi import Request, HTTPException @app.exception_handler(HTTPException) async def http_exception_handler(request: Request, exc: HTTPException): app_logger.[1]('HTTP error occurred: %s', exc.detail, exc_info=[2]) return JSONResponse(status_code=exc.status_code, content=[3])
Use error to log the error message. Setting exc_info=True includes the stack trace. The JSON response content should have a key like 'message' with the error detail.