Writing a Simple Logging Application
Imagine you have a small web application and want to see what users are doing: who opened the home page and who clicked a button. In real DevOps work, tracking these actions helps you understand user behavior and catch issues early.
You create a simple Flask app that shows a welcome message and reacts when a button is clicked. Each action is recorded in a log file, giving you a first look at how logging works before connecting it to ELK for analysis.
What You Will Do
The app has two routes: one for the home page and one for a "button" click. Every time someone visits a route or clicks the button, an event is recorded in the log. This helps you see exactly what users are doing and provides a foundation for future analysis.
app.py
You create a Flask application object that handles routes and incoming requests. Then you set up logging using logging.basicConfig
so all user actions are recorded in the file /logs/app.log
, including the timestamp, event level, and message.
The two routes show how the app works: /
returns a welcome message and logs when the home page is opened, while /click
logs a button click and returns a text response. Finally, the server runs on all interfaces at port 5000, allowing you to test the app and see events in the log file.
1. Where are the user actions recorded?
2. Which route should you open to log a button click?
Thanks for your feedback!
Ask AI
Ask AI
Ask anything or try one of the suggested questions to begin our chat
Can you explain how logging is set up in the Flask app?
What kind of information is recorded in each log entry?
How can I use these logs for further analysis later?
Awesome!
Completion rate improved to 3.7
Writing a Simple Logging Application
Swipe to show menu
Imagine you have a small web application and want to see what users are doing: who opened the home page and who clicked a button. In real DevOps work, tracking these actions helps you understand user behavior and catch issues early.
You create a simple Flask app that shows a welcome message and reacts when a button is clicked. Each action is recorded in a log file, giving you a first look at how logging works before connecting it to ELK for analysis.
What You Will Do
The app has two routes: one for the home page and one for a "button" click. Every time someone visits a route or clicks the button, an event is recorded in the log. This helps you see exactly what users are doing and provides a foundation for future analysis.
app.py
You create a Flask application object that handles routes and incoming requests. Then you set up logging using logging.basicConfig
so all user actions are recorded in the file /logs/app.log
, including the timestamp, event level, and message.
The two routes show how the app works: /
returns a welcome message and logs when the home page is opened, while /click
logs a button click and returns a text response. Finally, the server runs on all interfaces at port 5000, allowing you to test the app and see events in the log file.
1. Where are the user actions recorded?
2. Which route should you open to log a button click?
Thanks for your feedback!