Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Lernen Writing a Simple Logging Application | Section
Monitoring and Observability

bookWriting 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

app.py

copy

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?

question mark

Where are the user actions recorded?

Select the correct answer

question mark

Which route should you open to log a button click?

Select the correct answer

War alles klar?

Wie können wir es verbessern?

Danke für Ihr Feedback!

Abschnitt 1. Kapitel 2

Fragen Sie AI

expand

Fragen Sie AI

ChatGPT

Fragen Sie alles oder probieren Sie eine der vorgeschlagenen Fragen, um unser Gespräch zu beginnen

bookWriting a Simple Logging Application

Swipe um das Menü anzuzeigen

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

app.py

copy

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?

question mark

Where are the user actions recorded?

Select the correct answer

question mark

Which route should you open to log a button click?

Select the correct answer

War alles klar?

Wie können wir es verbessern?

Danke für Ihr Feedback!

Abschnitt 1. Kapitel 2
some-alt