A. A log entry with message 'Hello route accessed' at INFO level
B. No log will be written because app.logger is not configured
C. An error log because logging.basicConfig is missing a format
D. A warning log with message 'Hello route accessed'
Solution
Step 1: Check logging configuration
logging.basicConfig sets INFO level and file 'app.log'.
Step 2: Analyze app.logger usage
app.logger.info writes an INFO level log with given message.
Final Answer:
A log entry with message 'Hello route accessed' at INFO level -> Option A
Quick Check:
app.logger.info logs message at INFO [OK]
Hint: app.logger.info writes INFO logs if level allows [OK]
Common Mistakes:
Assuming app.logger needs extra setup beyond basicConfig
Confusing log levels INFO and WARNING
Thinking format is mandatory for logging
4. You set up logging in Flask with logging.basicConfig(filename='app.log', level=logging.ERROR) but notice that INFO logs still appear in app.log. What is the likely cause?
medium
A. The file app.log is not writable
B. logging.basicConfig does not control log levels
C. app.logger.info() does not respect logging levels
D. The root logger level was set before basicConfig and overrides it
Solution
Step 1: Understand basicConfig behavior
basicConfig only works if root logger has no handlers yet.
Step 2: Identify cause of wrong log levels
If root logger was configured earlier, basicConfig call is ignored, so level stays lower.
Final Answer:
The root logger level was set before basicConfig and overrides it -> Option D
Hint: basicConfig ignored if root logger already configured [OK]
Common Mistakes:
Believing basicConfig cannot set levels
Thinking app.logger ignores levels
Assuming file permission causes wrong logs
5. 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
A. Use print statements instead of logging for info and error messages
B. Call logging.basicConfig twice with different filenames and levels
C. Use two handlers: one FileHandler for error.log with level WARNING, another for info.log with level INFO, added to app.logger
D. Set app.logger level to INFO and write all logs to error.log only
Solution
Step 1: Understand multiple log files need multiple handlers
One handler per file with its own level filters logs accordingly.
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.
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
Quick Check:
Multiple handlers = multiple log files [OK]
Hint: Use multiple handlers for different log files and levels [OK]
Common Mistakes:
Calling basicConfig multiple times (only first works)
Logging all levels to one file without filtering
Using print instead of logging for production
Recommended
Ready to prove it?
Pass the test and this pattern moves unknownstrongwhile earning +1 Grip toward your certificate.