Skip to content

Instantly share code, notes, and snippets.

@wave2
Created February 14, 2013 08:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save wave2/4951248 to your computer and use it in GitHub Desktop.
Save wave2/4951248 to your computer and use it in GitHub Desktop.
This script was used to parse all logs in a folder and extract an ID along with request / response timings (for reporting purposes). It remembers the previous line as the logs were multi line entries and the time was stored on the line above the ID (fun). Quick a dirty hack that allowed Excel to finish the job.
require 'date'
files = Dir.glob('//myserver/myfolder/*.log')
files.each do |file|
previousLine = ""
requests = Hash.new
responses = Hash.new
File.readlines(file).each do |line|
if (line.match(/ref \[ (.*) \]/))
if (line.match(/request for the ID/))
if (previousLine.match(/Date :/))
requests[line.match(/ref \[ (.*) \]/)[1]] = previousLine.match(/Date : \[(.*)\] Millis/)[1]
end
end
if (line.match(/response of the ID/))
if (previousLine.match(/Date :/))
responses[line.match(/ref \[ (.*) \]/)[1]] = previousLine.match(/Date : \[(.*)\] Millis/)[1]
end
end
else
previousLine = line
end
end
requests.each_pair do |k,v|
if (v != nil && responses[k] != nil)
print k + "," + DateTime.strptime(v, '%a %b %d %H:%M:%S %Z %Y').strftime('%Y-%m-%d %H:%M:%S').to_s + "," + DateTime.strptime(responses[k], '%a %b %d %H:%M:%S %Z %Y').strftime('%Y-%m-%d %H:%M:%S').to_s + "\n"
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment