Free lab Real Python 3. Zero installs. Your code stays in this browser. Open the playground

Capstone: Server Log Analyzer

25 min 60 XP
Study loop Read Predict Run Tweak Prove Review
Lesson 5 of 5 · View course roadmap
Step 1

Learn the idea

The capstone. Real servers write logs like:

2026-07-19 12:01:33 GET /api/courses 200
2026-07-19 12:01:35 GET /api/missing 404

Ops engineers get paid to answer: how many requests? how many errors? which endpoint is hottest? You now have every tool required:

  • splitlines() + split() to parse each line
  • Conditions to classify status codes
  • Counter to rank endpoints
  • f-strings to report

This exact pattern — parse, filter, aggregate, report — is the backbone of data engineering. Nail this and you're ready for real-world scripting work.

Where you'll use this

This is a junior DevOps/data task verbatim: 'how many 5xx errors since the deploy?' Splunk, Datadog and the ELK stack are this loop at planetary scale — you just built the core of an observability product.

Common mistakes

  • Assuming every line is well-formed — production logs contain partial lines and garbage; guard with a length check or try/except per line.
  • Reading a huge file into one string — iterate line by line and it streams in constant memory (works on files bigger than RAM).
  • Counting with nested ifs when Counter does it declaratively — less code, fewer bugs.

Pro tip

Add argparse and your script becomes a real CLI tool: python analyze.py access.log --since 12:00. That jump — from script to tool a teammate can run — is what gets automation adopted.

Step 2

Try it yourself

Blank · autosaved

The lesson example is loaded and ready — press Run, then change something and run it again. Breaking it is part of learning. Want a clean slate? Tap “New blank”.

PYexample.py
+ Enter to run
Output appears here…
Step 3

Pass the challenge +60 XP

Blank · autosaved

Analyze the log in the starter. Print: total number of requests, number of error responses (status ≥ 400), and the most-requested path.

Target output
6
2
/api/courses
PYchallenge.py
Run your code to check it…
Step 4

Check your understanding

1. Counter(paths).most_common(1) returns…
Last step

Your notes (saved on this device)

Tip: use and to move between lessons, K to search everything.

Your next ten minutes

Write Python that does something useful.

Start free. No install, no card, no passive video marathon.

Start learning free → Explore the path