I have a rails application and I have setup logrotate for the logs.
The logs are like production.log
, sidekiq.log
, cron.log
in the directory /home/username/myapp/log/
. I want the rotated logs should be named like production.log-server-1-2016-08-02-1470119678.gz
. This type of file is also present but one more file is there which is named like production.log-server-1-2016-08-02-1470119678.gz-server-1-2016-08-03-1470206339-server-1-2016-08-03-1470225672.gz
.
Below are my configuration for logrotate
/etc/logrotate.d/myapp
/home/user/myapp/log/*.log {
weekly
size 10M
missingok
rotate 7
compress
delaycompress
copytruncate
#create 0640 ubuntu ubuntu
su ubuntu ubuntu
sharedscripts
prerotate
endscript
postrotate
endscript
}
/etc/logrotate.conf
# see "man logrotate" for details
# rotate log files weekly
daily
size 10M
# use the syslog group by default, since this is the owning group
# of /var/log/syslog.
su root syslog
# keep 4 weeks worth of backlogs
rotate 4
# create new (empty) log files after rotating old ones
create
# use date as a suffix of the rotated file
dateext
dateformat -server-1-%Y-%m-%d-%s
# uncomment this if you want your log files compressed
compress
# packages drop log rotation information into this directory
include /etc/logrotate.d
# no packages own wtmp, or btmp -- we'll rotate them here
/var/log/wtmp {
missingok
weekly
size 500K
create 0664 root utmp
rotate 1
}
/var/log/btmp {
missingok
weekly
size 500K
create 0660 root utmp
rotate 1
}
# system-specific logs may be configured here
Any help? Basically I want the log file should be named like production.log-server-1-date-month-year-time.gz
and it should be rotated if the file size increases more than 10mb or weekly.