I have a Ruby on Rails application running on Docker and would like to rotate my production logs every day. In the spirit of keeping everything self-contained, I would like to keep the log rotation on Docker itself as well. Here's the logrotate configuration on my Docker container:
/etc/logrotate.conf
# rotate log files weekly
weekly
# keep 1 week worth of backlogs
rotate 1
# create new (empty) log files after rotating old ones
create
# use date as a suffix of the rotated file
dateext
# uncomment this if you want your log files compressed
#compress
# packages drop log rotation information into this directory
include /etc/logrotate.d
# system-specific logs may be also be configured here.
# Rotate Rails logs
/myapp/log/*.log {
daily
missingok
rotate 7
compress
delaycompress
notifempty
copytruncate
}
Permissions for /etc/logrotate.conf:
-rw-r--r-- 1 root root 656 Jul 13 02:06 /etc/logrotate.conf
After a day, my log file has not been rotated. I know this isn't an issue with my container being recreated because it's been running for 6 days.
When I go to test it, I get an error message on every line:
> logrotate -d /myapp/log/production.log
...
> error: production.log:56257 unknown option 'I' -- ignoring line
> error: production.log:56258 unknown option 'I' -- ignoring line
> error: production.log:56259 unknown option 'I' -- ignoring line
Here are the permissions on my production.log:
-rw-r--r-- 1 root root 10868754 Jul 14 12:42 /myapp/log/production.log
And when I check what's in the log file, the contents are indeed there:
I, [2022-07-13T02:48:23.666904 #1] INFO -- : Raven 3.1.0 ready to catch errors
I, [2022-07-13T03:00:18.483790 #8] INFO -- : Raven 3.1.0 ready to catch errors
I, [2022-07-13T03:00:34.021416 #22] INFO -- : Started GET "/healthcheck" for xxx.xx.xx.xx at 2022-07-13 03:00:34 +0000
I, [2022-07-13T03:00:34.026047 #22] INFO -- : Processing by HealthcheckController#show as HTML
I, [2022-07-13T03:00:34.027170 #29] INFO -- : Started GET "/healthcheck" for xxx.xx.xx.xx at 2022-07-13 03:00:34 +0000
I, [2022-07-13T03:00:34.031331 #29] INFO -- : Processing by HealthcheckController#show as HTML
I, [2022-07-13T03:00:34.038132 #20] INFO -- : Started GET "/healthcheck" for xxx.xx.xx.xx at 2022-07-13 03:00:34 +0000
I, [2022-07-13T03:00:34.042771 #20] INFO -- : Processing by HealthcheckController#show as HTML
I, [2022-07-13T03:00:34.040177 #20] INFO -- : Started GET "/healthcheck" for xxx.xx.xx.xx at 2022-07-13 03:00:34 +0000
I, [2022-07-13T03:00:34.221546 #20] INFO -- : Processing by HealthcheckController#show as HTML
What can I do to get logrotate
to rotate my logs?