Skip to main content

LogRotate

Add a service to logrotate

vi /etc/logrotate.d/name_of_file

/var/log/some_dir/somelog.log {
        su root root
        missingok
        notifempty
        compress
        size 5M
        daily
        create 0600 root root
}

  • su - run a root user
  • missingok - do not output error if logfile is missing
  • notifempty - donot rotate log file if it is empty
  • compress - Old versions of log files are compressed with gzip(1) by default
  • size - Log file is rotated only if it grow bigger than 20k
  • daily - ensures daily rotation
  • create - creates a new log file wit permissions 600 where owner and group is root user
Force run a logrotate
logrotate -f /etc/logrotate.conf

Once it's all done no need to do anything else, log rotate already runs in /etc/cron.daily/logrotate