Lesson 46/48 ยท ๐ Working with the Real World
๐ Working with the Real WorldLesson 46/48
Phase 8 ยท Working with the Real World45 min
Capstone: Log File Analyzer
Build a real tool that parses server logs and produces a report
Your first real tool. You'll build a log file analyzer that takes a web server access log and produces a summary report: total requests, error rate, top endpoints.
This uses: string manipulation, dictionaries, loops, functions, and f-strings, everything from Phases 1-5.
This uses: string manipulation, dictionaries, loops, functions, and f-strings, everything from Phases 1-5.
How would you approach this? Think first, then expand.
Sample log format (Apache/Nginx CLF)python
# Each log line looks like:
# 192.168.1.1 - - [09/Mar/2026:09:15:32] "GET /api/users HTTP/1.1" 200 1234
# IP - - [timestamp] "METHOD path protocol" status bytes
SAMPLE_LOG = """192.168.1.1 - - [09/Mar/2026] "GET /api/users HTTP/1.1" 200 1234
10.0.0.5 - - [09/Mar/2026] "POST /api/login HTTP/1.1" 401 89
192.168.1.2 - - [09/Mar/2026] "GET /api/users HTTP/1.1" 200 1234
10.0.0.5 - - [09/Mar/2026] "GET /api/data HTTP/1.1" 500 45
192.168.1.1 - - [09/Mar/2026] "GET /api/users HTTP/1.1" 200 1234
10.0.0.5 - - [09/Mar/2026] "GET /api/health HTTP/1.1" 200 12"""๐In the Real World...
This is the starting point for real observability tooling. Production log analyzers like Splunk, Datadog, and ELK all do exactly this, parse structured text, aggregate by key, report anomalies.
๐ฏ
Phase Complete!
Working with the Real World
You can now read files, parse JSON, and use regex. Describe how you'd build a script that reads a server log file, extracts all 5xx errors, and saves them to a JSON report.
0/500
Practice Exercises
0/3 solvedExercise 1 of 3mediumGuided
โฑ 00:00Parse Log Lines
Parse each log line and extract: IP address, HTTP method, path, and status code.
For the first line of SAMPLE_LOG, print:
For the first line of SAMPLE_LOG, print:
IP: 192.168.1.1 | Method: GET | Path: /api/users | Status: 200solution.py
1 / 3
Exercise 2 of 3medium
โฑ 00:00Count Requests per Endpoint
Count how many requests hit each path and print them sorted by count (descending).
Using SAMPLE_LOG, expected output:
Using SAMPLE_LOG, expected output:
/api/users: 3/api/login: 1/api/data: 1/api/health: 1solution.py
2 / 3
Exercise 3 of 3hard
โฑ 00:00Calculate Error Rate
Calculate the percentage of requests with status 4xx or 5xx.
Using SAMPLE_LOG (6 total requests, 2 errors: 401 and 500):Expected output:
Using SAMPLE_LOG (6 total requests, 2 errors: 401 and 500):Expected output:
Error rate: 33.33%solution.py
3 / 3
Solve all 3 exercises to unlock completion