Created
January 2, 2013 12:49
-
-
Save abriening/4434375 to your computer and use it in GitHub Desktop.
Reads a rails log and extracts the given parameters, prints CSV.
This file contains hidden or 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
#!/usr/bin/env ruby | |
file = ARGV.shift | |
parameters = ARGV | |
unless file && !parameters.empty? | |
puts <<-end_usage | |
Usage #{$0} logfile param [param, ...] | |
Reads a rails log and extracts the given parameters, prints CSV. | |
Useful to include [action, controller] in parameters. | |
end_usage | |
exit | |
end | |
STDOUT.puts (%w[timestamp] + parameters).join(',') | |
pattern = %r!(^[\S]+)? .*Parameters.*"(?:#{parameters.join('|')})"! | |
File.open file do |f| | |
f.each do |line| | |
if line =~ pattern | |
row = [$1] | |
parameters.each do |attr| | |
line =~ %r!"#{attr}"=>"([^"]*)"! | |
row << $1 | |
end | |
STDOUT.puts row.join(',') | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment