views:

478

answers:

3

Hello,

I have a daemon that runs constantly which fills up the log file(development.log or production.log) pretty quickly. What is the best way to delete the log file after certain size or delete the portion before certain day.

Thanks,

Tam

+3  A: 

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.

Lars Haugseth
A: 

Or you can delegate logging to syslog

Hemant Kumar
+1  A: 
config.logger = Logger.new(config.log_path, 50, 1.megabyte)

but beware that multiple mongrels can have issues with this.

srboisvert