I'm running Rails 5 on Ubuntu 14.04. Is there a way to rotate my logs without relying on the Linux logrotate system? I have this set up ...
myuser@myapp:~$ cat /etc/logrotate.d/myapp
/home/rails/myapp/log/*.log {
daily
missingok
rotate 2
compress
delaycompress
notifempty
copytruncate
}
but yet my logs never rotate. Behold how bloated they are ...
myuser@myapp:~$ ls -al /home/rails/myapp/log/
total 3958356
drwxr-xr-x 2 rails rails 4096 Jul 3 22:31 .
drwxr-xr-x 15 rails rails 4096 Sep 21 17:21 ..
-rw-rw-r-- 1 rails rails 0 Jun 22 10:22 development.log
-rw-rw-r-- 1 rails rails 14960 Jun 1 22:39 development.log.1
-rw-rw-r-- 1 rails rails 0 Oct 22 2016 .keep
-rw-r--r-- 1 rails rails 198362787 Oct 31 16:28 production.log
-rw-r--r-- 1 rails rails 8615654 Jul 3 22:31 production.log.1
-rw-r--r-- 1 rails rails 640621243 Jun 29 13:16 production.log.2.gz
-rw-rw-r-- 1 rails rails 2856792698 Oct 31 17:12 sidekiq.log
-rw-rw-r-- 1 rails rails 348853619 Jul 3 22:31 sidekiq.log.1
-rw-rw-r-- 1 rails rails 0 Jul 3 22:31 test.log
-rw-rw-r-- 1 rails rails 54246 Jul 3 22:31 test.log.1
Is there another way to get the logs rotated or is there a way to fix the configuration I have included?
Edit: Here's the cron script that's set
myuser@myapp:~$ cat /etc/cron.daily/logrotate
#!/bin/sh
# Clean non existent log file entries from status file
cd /var/lib/logrotate
test -e status || touch status
head -1 status > status.clean
sed 's/"//g' status | while read logfile date
do
[ -e "$logfile" ] && echo "\"$logfile\" $date"
done >> status.clean
mv status.clean status
test -x /usr/sbin/logrotate || exit 0
/usr/sbin/logrotate /etc/logrotate.conf
Edit: Per the comment I tried adding this to my config/environment/production.rb file ...
config.logger = ActiveSupport::Logger.new(config.paths['log'].first, 1, 50 * 1024 * 1024)
but the logs get ever bigger without being rotated.
/etc/cron.daily
(probablyetc/cron.daily/logrotate
), what are its contents? What are the contents of the global logrotate conf file (probably at/etc/logrotate.conf
)? – Chaconne/etc/cron.daily/logrotate
and it's already there, so changing the confs should start getting things rotated. – Chaconne/etc/logrotate.conf
to the question, as the settings in there are combined with the ones in yourmyapp
conf file. – Chaconnelogrotate -d /etc/logrotate.conf
? And what does/var/lib/logrotate/status
look like? – Chaconne