Rails’s production logs contain a wealth of information, but I have found them to be rather parsimonious with it. Aside from manually reading through them, I have never found a good tool for parsing them into programmatically usable data (speed analyzers excepted).

“Google Analytics you moron!” Honestly I’ve never used it, because 1) it seems like a beast to use effectively, 2) I’m not sure it answers the questions I’m asking, and 3) the information I want is already sitting on my server, if I could only get at it.

“Apache/Nginx logs you moron!” No, they only contain a subset of the information in the Rails logs.

I decided I should be able to express what I wanted in a declarative fashion, using a simple DSL. I came up with this:

hit :bad_login, :path => '/login', :method => :post, :status => 401 do
  puts "Bad login with #{params[:username]} from #{ip}"
end

After I figured out how to actually write a DSL in Ruby, it turned out to be pretty trivial. Trivial enough that I’m wondering why it didn’t exist years ago and gain tremendous popularity. Please let me know if I’m missing anything.

Beaver

I’m calling the resulting project Beaver. It’s still what I’d call experimental, but I’m using it regularlly without any real problems. I’d love to hear some feedback from the Rails community about how others are making good use of their log files, because I can’t find any chatter about it.