Bird
0
0

You want to log errors and warnings to a file error.log and info messages to info.log in your Flask app. Which setup correctly achieves this?

hard📝 Best Practice Q15 of 15
Flask - Deployment
You want to log errors and warnings to a file error.log and info messages to info.log in your Flask app. Which setup correctly achieves this?
AUse print statements instead of logging for info and error messages
BCall logging.basicConfig twice with different filenames and levels
CUse two handlers: one FileHandler for error.log with level WARNING, another for info.log with level INFO, added to app.logger
DSet app.logger level to INFO and write all logs to error.log only
Step-by-Step Solution
Solution:
  1. Step 1: Understand multiple log files need multiple handlers

    One handler per file with its own level filters logs accordingly.
  2. Step 2: Check options for multiple handlers

    Use two handlers: one FileHandler for error.log with level WARNING, another for info.log with level INFO, added to app.logger correctly uses two FileHandlers with different levels added to app.logger.
  3. Final Answer:

    Use two handlers: one FileHandler for error.log with level WARNING, another for info.log with level INFO, added to app.logger -> Option C
  4. Quick Check:

    Multiple handlers = multiple log files [OK]
Quick Trick: Use multiple handlers for different log files and levels [OK]
Common Mistakes:
MISTAKES
  • Calling basicConfig multiple times (only first works)
  • Logging all levels to one file without filtering
  • Using print instead of logging for production

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Flask Quizzes