Sorry this page looks weird. It was automatically migrated from my old blog, which had a different layout and different CSS.

Filter Rails Logs

Rails logs each request over multiple lines. It’s nice to have so much information but it invariably makes searching the logs a messy process.

Some people are writing drop-in replacements for the Rails logger which log each request on a single line.

In the meantime I use cack to search/filter my Rails logs. Give it a pattern and it will pull out every request block matching the pattern.


Typical scenario

Sometimes customers phone me with a problem. Each customer has their own subdomain, which I log for every request. cack lets me extract their activity from the log, making it much easier to see what’s going on.

$ cack customer-subdomain production.log
$ vim production.log.out

It’s already helped me solve several customer problems faster.

I’ve also used cack to filter by IP address and controller action.


The script has a few limitations:

Andrew Stewart • 13 April 2012 • ProductivityTools
You can reach me by email or on Twitter.