"how to delete rails log file after certain size" Code Answer

2

the best way is to set up log rotation, but how you do this is very platform dependent, so you should add a comment about what you're using, both for development and production.

for our apps running on linux, we have a file /etc/logrotate.d/appname for each app, that looks something like this:

/path/to/rails_root_for_app/log/production.log {
    daily
    missingok
    rotate 7
    compress
    delaycompress
    notifempty
    create 640 capistrano capistrano
}

this will move the log into a new file once a day, keeping a compressed backup file for each of the last 7 days.

if you just want to empty the file without keeping any of the data in it while the daemon is running, simply do this from a shell:

> /path/to/rails_root_for_app/log/development.log

this will truncate the file to 0 bytes length.

By zord on April 4 2022
Only authorized users can answer the Search term. Please sign in first, or register a free account.