Cleaning up with clearing rake tasks.

Published on July 23, 2024
Written by Daniel Schoppmann

It's like anywhere else in life: If you do a lot of crafting, you're going to get dust, and you're going to have to clean it up from time to time. Otherwise, it's a mess to work in.
As developers, we tend to have a good eye for refactoring, but do we have the same eye for our logs?

Especially in development: Every requests is logged, every request might create cache files, every test run might produce screenshots etc.
In large Rails application, the local log and tmp directories can grow quite large. When was the last time you checked for the file size of your local log files?

du -hc */**/*.log

Don't be surprised to see quite large numbers here. It's a good thing that Rails comes with practical clearing tasks - in the form of rake tasks:

# Truncate all/specified *.log files in log/ to zero bytes (specify which logs with LOGS=test,development)
bin/rails log:clear

# Clear cache, socket and screenshot files from tmp/ (narrow w/ tmp:cache:clear, tmp:sockets:clear, tmp:screen...
bin/rails tmp:clear

The description speaks for itself.

Hint: If your Rails app already runs on Rails 7.1 or higher, there is also a new log_file_size config available now. It defaults to 100 MB in the development and test environment.

So always keep an eye for large files in your local app environment!

Subscribe to get future articles via the RSS feed .