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?
Merci pour vos commentaires !
Demandez à l'IA
Demandez à l'IA
Posez n'importe quelle question ou essayez l'une des questions suggérées pour commencer notre discussion
Génial!
Completion taux amélioré à 16.67
Writing a Simple Logging Application
Glissez pour afficher le 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?
Merci pour vos commentaires !