Challenge - 5 Problems
Logging Mastery in Production
Get all challenges correct to earn this badge!
Test your skills under time pressure!
💻 Command Output
intermediate2:00remaining
What is the output of this Flask logging configuration?
Given the following Flask app logging setup, what will be printed to the console when a request is made?
Flask
import logging from flask import Flask app = Flask(__name__) logging.basicConfig(level=logging.WARNING) @app.route('/') def home(): app.logger.debug('Debug message') app.logger.warning('Warning message') return 'Hello' if __name__ == '__main__': app.run()
Attempts:
2 left
💡 Hint
Check the logging level set by basicConfig and which messages are shown at that level.
✗ Incorrect
The logging level is set to WARNING, so only WARNING and above messages are printed. DEBUG messages are ignored.
❓ Configuration
intermediate2:00remaining
Which logging configuration writes logs to a file with rotation in Flask?
Select the correct Flask logging setup that writes logs to a file named 'app.log' and rotates the file after it reaches 1MB, keeping 3 backups.
Attempts:
2 left
💡 Hint
Look for a handler that rotates based on file size, not time.
✗ Incorrect
RotatingFileHandler rotates logs based on file size. TimedRotatingFileHandler rotates based on time intervals.
❓ Troubleshoot
advanced2:00remaining
Why are Flask logs not appearing in production with Gunicorn?
You deployed a Flask app with Gunicorn. Your Flask app uses app.logger.warning('Test'). But no logs appear in the console or files. What is the most likely cause?
Attempts:
2 left
💡 Hint
Consider how Gunicorn manages logging separately from Flask.
✗ Incorrect
Gunicorn manages its own logging and may override or ignore Flask's logger unless configured properly.
✅ Best Practice
advanced2:00remaining
What is the best practice for logging sensitive information in production Flask apps?
Which option describes the best practice for handling sensitive data in logs for a Flask production app?
Attempts:
2 left
💡 Hint
Think about privacy and security risks in logs.
✗ Incorrect
Logging sensitive data can cause security risks. Best practice is to avoid logging such data or mask it.
🔀 Workflow
expert3:00remaining
Order the steps to set up centralized logging for a Flask app in production using Docker and ELK stack.
Arrange the steps in the correct order to enable centralized logging for a Flask app running in Docker containers, sending logs to an ELK (Elasticsearch, Logstash, Kibana) stack.
Attempts:
2 left
💡 Hint
Think about setting up infrastructure before configuring app and forwarding logs.
✗ Incorrect
First deploy ELK stack, then configure app logging format, then set Docker to forward logs, finally visualize in Kibana.