Monday 7 September 2009

Finding the bad parts in a log file

This little script makes things easier by extracting the errors out of a rails log file
#!/usr/bin/env ruby

text = ''
completed = false
total = 0
good = 0

ARGF.each do |l|
if l =~ /^Processing /
puts text if completed == false and text.size > 0
text = ''
completed = false
total += 1
elsif l =~ /^Completed /
completed = true
good += 1
end
text << l
end

puts text if completed == false and text.size > 0

$stderr.puts "Read #{total} transactions, #{total - good} were errors"

To use it you do this: striplog.rb development.log > development.log.errors. It will print out a summary line at the end to show you how many errors it found

No comments:

Post a Comment