How to add a new log file to logrotate in Ubuntu?

How to add a new log file to logrotate in Ubuntu?

  1. Create the logrotate configuration file for the new log file. This should include information regarding the path to the log file, how often and when the log should be rotated, how many files should be rotated and when the rotated files should be deleted.

  2. Copy the configuration file to /etc/logrotate.d/ directory.

  3. Run the logrotate command manually to rotate the log file:
    sudo logrotate -f /etc/logrotate.d/config_file_name

  4. To automatically run logrotate, edit /etc/crontab and add a line to run the logrotate command. Alternatively, you may create a cron job to run the logrotate command at a specified time.