I just woke up to some unhappy clients because their website was down.
The log file was an obsurd size, so big that there was no more space
left on the disk.
Is it possible to turn logging off, or at least truncate it every night
or something?
Thanks for your help.
Ben J. wrote:
I just woke up to some unhappy clients because their website was down.
The log file was an obsurd size, so big that there was no more space
left on the disk.
Is it possible to turn logging off, or at least truncate it every night
or something?
Thanks for your help.
Hi Ben,
In config/environment.rb make sure that log_level = :info is set. You
may also want to set up a cron job to rotate your logs nightly and
delete or archive them out once they are x number of days/weeks old.
Phil
Does rails come with, or is there a plugin for, rotating logfiles?
i.e. similar to log4j in the java world
If you are using some form of unix you could just use logwatch… same
as
for most logs on your system (apache, smtp, etc.)
Take care,
Sean
I typed this off the top of my head without testing so proceed carefully
and
make backups!
Here’s a quick answer if it’s a unix system, make a script that does the
following:
DATE=date +"%Y%m%d"
cp /PATH_TO_LOGS/production.log /PATH_TO_LOGS/production.log.$DATE
cp /dev/null /PATH_TO_LOGS/production.log
find /PATH_TO_LOGS -name “production.log." ! -name ".gz” -mtime +7
-exec
gzip {} ;
find /PATH_TO_LOGS -name “production.log.*” -mtime +14 -exec rm {} ;
This will copy the log to a datestamped file (you can copy to another
dir if
you want). Then it will null out the current log. Then it will
compress
any datestamped log older then a week. Then it will remove any
datestamped
log older then 14 days.
You don’t have to remove it, you can move the file somewhere with more
storage if you want with a line like this:
find /PATH_TO_LOGS -name “production.log.*” -mtime +14 -exec mv {}
/PATH_TO_ARCHIVE ;
Put it in your crontab to run every night:
0 30 * * * /PATH_TO_SCRIPT/clean_logs.sh
Try not to do it right at midnight. Other things may be happening at
that
moment.
Ben wrote:
I just woke up to some unhappy clients because their website was down.
The log file was an obsurd size, so big that there was no more space
left on the disk.
Is it possible to turn logging off, or at least truncate it every night
or something?
How about using logrotate? You can control the size of the log file and
have it backed up for N number of days.
Long