Skip to content

Instantly share code, notes, and snippets.

@rwrrll
Created October 8, 2014 17:03
Show Gist options
  • Save rwrrll/ef1237f9777e04d35531 to your computer and use it in GitHub Desktop.
Save rwrrll/ef1237f9777e04d35531 to your computer and use it in GitHub Desktop.
Really quick and dirty hack to "parse" Rails log files looking for a request/response pair.
filename = ARGV.first
puts "Opening #{filename}"
file = File.open(filename)
puts "Reading contents"
contents = file.read.encode('UTF-8', invalid: :replace)
puts "Splitting into requests"
requests = contents.split("\n\n\n")
puts "Found #{requests.length} requests"
puts "Looking for matches"
matches = requests.select do |request|
lines = request.split("\n")
lines.first.match(/^Started GET "\/" for/) && !lines.last.match(/^Completed 200/)
end
puts "Found #{matches.length} matches"
matches.each do |match|
puts "\n\n"
puts match
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment