Normally, logrotate is run as a daily cron job. It will not modify a log multiple times in one day unless the criterion for that log is based on the log's size and logrotate is being run multiple times each day, or unless the -f or --force option is used.
The default configuration file is:
/etc/logrotate.conf
Service or server specific configurations are stored in
/etc/logrotate.d/
Force Log Rotation
logrotate -vf CONFIG_FILE
Force Log Rotation default configuration
logrotate -vf /etc/logrotate.conf
Options
-d, --debug Dry run logrotate.
-f, --force Force logrotate.
-v, --verbose Shows more information.
Sample logrotate configuration file for /var/log/apache2/access_log
/var/log/apache2/access_log {
compress
dateext
maxage 365
rotate 99
size=+4096k
notifempty
missingok
create 644 root root
postrotate
/etc/init.d/apache2 reload
endscript
}
Sample logrotate configuration file for /var/log/nginx/access.log
/var/log/nginx/access.log {
size 100k
rotate 3
compress
delaycompress
notifempty
postrotate
# the same [ -f /var/run/nginx.pid ] && kill -USR1 `cat /var/run/nginx.pid`
nginx -s reopen
endscript
sharedscripts
}
compress Old versions of log files are compressed with gzip by default.
delaycompress Postpone compression of the previous log file to the next rotation cycle. This only has effect when used in combination with compress. It can be used when some program cannot be told to close its logfile and thus might continue writing to the previous log file for some time.
copytruncate Truncate the original log file in place after creating a copy, instead of moving the old log file and optionally creating a new one. It can be used when some program cannot be told to close its logfile and thus might continue writing (appending) to the previous log file forever. Note that there is a very small time slice between copying the file and truncating it, so some logging data might be lost. When this option is used, the create option will have no effect, as the old log file stays in place.
create Immediately after rotation the log file is created (with the same name as the log file just rotated). mode specifies the mode for the log file in octal, owner specifies the user name who will own the log file, and group specifies the group the log file will belong to. Any of the log file attributes may be omitted, in which case those attributes for the new file will use the same values as the original log file for the omitted attributes.
daily Log files are rotated every day.
weekly Log files are rotated if the current weekday is less than the weekday of the last rotation or if more than a week has passed since the last rotation.
monthly Log files are rotated the first time logrotate is run in a month (this is normally on the first day of the month).
yearly Log files are rotated if the current year is not the same as the last rotation.
maxage Remove rotated logs older than <count> days. The age is only checked if the logfile is to be rotated. The files are mailed to the configured address if maillast and mail are configured.
minsize Log files are rotated when they grow bigger than size bytes, but not before the additionally specified time interval (daily, weekly, monthly, or yearly).
size Log files are rotated only if they grow bigger then size bytes. If size is followed by k, the size is assumed to be in kilobytes. If the M is used, the size is in megabytes, and if G is used, the size is in gigabytes.
rotate Log files are rotated count times before being removed or mailed to the address specified in a mail directive. If count is 0, old versions are removed rather than rotated.
sharedscripts If sharedscripts is specified, the scripts inside postrotate/endscript are only run once, no matter how many logs match the wildcarded pattern, and whole pattern is passed to them.
postrotate/endscript The lines between postrotate and endscript (both of which must appear on lines by themselves) are executed (using /bin/sh) after the log file is rotated.
Documentation: https://linux.die.net/man/8/logrotate