Purging logs

Hello.

Sorry if this is too simple a question. How do I go about
automatically purging logs of an application in production? The
application runs on a Windows server.

Thanks.

Pepe

$ rake -T log
(in /Users/philip/Work/Careers.org/web/trunk)
rake log:clear # Truncates all *.log files in log/ to zero bytes

Whether or not you need to restart any services after that depends on
your setup.

-philip

I'm sorry but I am not very familiar with rake and I don't understand
your posting.

Doesn't the $ in your command mean that it is run manually? What I
need is for the application/server to take care of the logs itself and
delete log information older than, for example, x amount of days.

Also, why would I need to restart services if I am just deleting data
from a text file such as 'production.log' or 'server.log'? Would the
files need to be locked to purge them?

Thanks

Pepe

I'm sorry but I am not very familiar with rake and I don't understand
your posting.

Doesn't the $ in your command mean that it is run manually?

Yes, but you could also run that via cron to make it automatic.

What I
need is for the application/server to take care of the logs itself and
delete log information older than, for example, x amount of days.

To do that you need to configure one of the other logging mechanism's
to split the logs up by day and automatically purge them. Google
around for plugins to do this (if it isn't already built in to rails,
i don't remember)

Also, why would I need to restart services if I am just deleting data
from a text file such as 'production.log' or 'server.log'? Would the
files need to be locked to purge them?

If another process has a file open when you remove it, the OS doesn't
really remove it until that first process closes the file. Which if
it's a web server, it may never do. So you think you've removed it,
but it will keep increasing in size.

-philip

Thanks!

Pepe

That magic mechanism is called logrotate and it’s built into any Unix/Linux based system.

In /etc/logrotate.d/, create a new file (you can name it whatever you want, the app name for example), then put this in it:

/path/to/your/railsapp/shared/log/production.log {

 copytruncate

 daily

 missingok

 rotate 14

 compress

 delaycompress

}

There should already be a crontab that fires it every day, since that’s what your Linux does to rotate its own logs.

And strangle enough, that information could be found on http://wiki.rubyonrails.org/rails/pages/DeploymentTips :wink:

Best regards

Peter De Berdt