Skip to content

Instantly share code, notes, and snippets.

@dolzenko
Created March 10, 2010 11:44
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 dolzenko/327785 to your computer and use it in GitHub Desktop.
Save dolzenko/327785 to your computer and use it in GitHub Desktop.
grep_rails_log_file
#!/usr/bin/env ruby
if ARGV.empty?
puts <<-USAGE
Use like tail -f log/production.log | #{ $PROGRAM_NAME } request_regexp
Examples:
Show only local requests:
tail -f log/production.log | #{ $PROGRAM_NAME } 127.0.0.1
Show only GET requests:
tail -f log/production.log | #{ $PROGRAM_NAME } GET
Show only requests to /updates path:
tail -f log/production.log | #{ $PROGRAM_NAME } /updates
USAGE
exit(0)
end
request_regexp = /#{ ARGV[0] }/
STDIN.slice_before(/Started (GET|POST|PUT|DELETE)/).each do |request_log|
puts request_log if request_log.first =~ request_regexp
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment