Created
June 23, 2014 15:50
-
-
Save Partyschaum/9826450851908f0f0af2 to your computer and use it in GitHub Desktop.
Transform Papertrail logfiles into Oink-readable Hodel 3000 compliant ones
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'date' | |
logfile = ARGV.first | |
if logfile.nil? || !File.exists?(logfile) | |
puts 'No logfile given!' | |
exit! | |
end | |
IO.foreach(logfile).each do |line| | |
# papertrail archived log columns | |
id, generated_at, received_at, source_id, source_name, source_ip, facility_name, severity_name, program, message = line.split "\t" | |
next unless message =~ /Oink|Memory|Instantiation/ | |
program.match(/app\/web\.(?<app_id>\d+)/) do |match| | |
next unless match | |
generated_at = DateTime.parse generated_at | |
# Jun 23 15:11:25 claptrap rails[21102]: Oink Log Entry Complete | |
date_time = generated_at.strftime '%b %d %T' | |
hodel_3000_compliant_line = "#{date_time} #{source_name} rails[#{match[:app_id]}]: #{message}" | |
puts hodel_3000_compliant_line | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment