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?
Grazie per i tuoi commenti!
Chieda ad AI
Chieda ad AI
Chieda pure quello che desidera o provi una delle domande suggerite per iniziare la nostra conversazione
Fantastico!
Completion tasso migliorato a 16.67
Writing a Simple Logging Application
Scorri per mostrare il 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?
Grazie per i tuoi commenti!