DevOps teams analyze application performance by parsing web server logs to identify slow endpoints. This drill teaches you to extract structured data from semi-structured log files using regular expressions with named groups. You'll parse Heroku router logs containing timestamps, HTTP methods, paths, service times, and status codes, then generate CSV output for analysis. Note: This drill parses CSV manually using string methods rather than Ruby's CSV library.
Use regex with named groups: /(?<name>pattern)/ for cleaner extraction
Match the timestamp at line start: /^(?<timestamp>\S+)/
Extract method with word characters: /(?<method>\w+)/
Parse service time: /service=(?<service>\d+)ms/ then .to_i
Skip non-matching lines with 'next unless match'
Build CSV manually: lines << "#{val1},#{val2},..."
parse_logs('server.log')
Parsed 5 requests, average service time: 60 ms
csv = parse_logs('server.log')
puts csv.lines.first.strip
Parsed 5 requests, average service time: 60 ms Timestamp,Method,Path,Service_Time_ms,Status
csv = parse_logs('server.log')
puts csv.lines[1..3].map { |l| l.split(',')[3] }.join(', ')
Parsed 5 requests, average service time: 60 ms 150, 80, 45
Console output will appear here...
Are you sure?
You're making great progress
Become a Ruby Pro
1,600+ problems to master every concept