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.
$ cack PATTERN LOGFILE
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:
- It writes to a file rather than stdout.
- You can’t configure the output filename.
- You can only pass it one filename at a time.