Bird
0
0

You wrote this code but no error logs appear when exceptions happen. What is the likely problem?

medium📝 Troubleshoot Q6 of 15
FastAPI - Error Handling
You wrote this code but no error logs appear when exceptions happen. What is the likely problem?
import logging
logger = logging.getLogger("app")
try:
    1 / 0
except Exception as e:
    logger.error("Error occurred", exc_info=True)
ASyntax error in the code
BThe exception is not caught properly
CLogging level is not set to show errors
Dlogger.error does not log exceptions
Step-by-Step Solution
Solution:
  1. Step 1: Check logging configuration

    By default, logging may not show error messages if level is too high or not set.
  2. Step 2: Confirm exception handling and logger usage

    Exception is caught and logger.error is called correctly, so issue is likely logging level.
  3. Final Answer:

    Logging level is not set to show errors -> Option C
  4. Quick Check:

    Set logging level to ERROR or lower to see error logs [OK]
Quick Trick: Set logging level to ERROR to see error logs [OK]
Common Mistakes:
MISTAKES
  • Assuming exception not caught
  • Thinking logger.error never logs exceptions
  • Ignoring logging configuration

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More FastAPI Quizzes