Question
How do I configure cPanel to rotate custom logs?
Answer
cPanel only rotates the default logs for select services. Custom logs and logs for other services are not rotated by cPanel itself. To rotate a custom log or a log for any other service, use a separate log rotation utility, such as logrotate.
- Connect to your server using SSH as the
rootuser. -
Logrotated uses configuration files inside
/etc/logrotate.d/to determine what logs are rotated and when. Create a new file in this directory named after the service:# touch /etc/logrotate.d/$servicename
Note: Replace '$servicename' with the actual name of the service to help you identify the file later.
-
Using a text editor, edit the new file you created and place in it a valid configuration. An example is below:
CONFIG_TEXT: /var/log/yourlogfile {
weekly
rotate 1
compress
missingok
}Note: This example rotates the logs weekly, while retaining 1 copy of the last logs before removing them. You must edit the path to match the log file you wish to rotate.
- Save the file, and it will be read the next time that logrotate runs. This is typically run once a day.
The above is provided as an example. Different logs may require different settings depending on your use case. To review all options for the service, you can review the man page for logrotate here:
Comments
0 comments
Article is closed for comments.