Quick Tip to Clean Up Rails Logs

Every few months I use this command to empty each and every one of my test.log and development.log files in the src folder of my laptop:

find ~/src \
  -maxdepth 6 \
  -type f \
  -mindepth 1 \
  \( -name "test.log" -or -name "development.log" \) \
  -exec truncate -s 0 {} \;

It works by…

  1. Finding files that match the name
  2. Using the truncate command to reduce the size of the file to 0 bytes

Instead of typing it out each time, I’ve created a quick alias in my .bash_profile when my shell loads:

alias truncate_devlogs='find . -maxdepth 6 -type f -mindepth 1 \( -name "test.log" -or -name "development.log" \) -exec truncate -s 0 {} \;'

Then when I remember to do so, or I wrap up work on a project, a quick truncate_devlogs recoups disk space and makes me feel better.


Now read this

Consistent Date Formatting in Ruby on Rails 5+

If you’ve ever dealt with dates in Rails, particularly accepting dates from user input and then displaying them, you’re familiar with two clunky experiences: The awful default month, day, year, hour, minute, second dropdowns The complete... Continue →