Log Rotation

This Item is only relevant for Linux.

In this Topic Hide

Configuring Log Rotation for Zend Server Logs

To Disable Log Rotation

 

In production environments, it is important to periodically compress/archive or truncate log file contents. Controlling your log file size prevents unnecessary disk consumption due to bloated log files. The following instructions describe how to override the native Zend Server log rotation mechanism and use logrotate.

Note:

logrotate is not part of the Zend Server product. To add this component you can use yum and aptitude, according to your distribution's repository.
For example, to locate the package in yum, run # yum search logrotate. You can do the same with aptitude too. If your distribution does not include this package in its repositories, you can download the source from here: https://fedorahosted.org/logrotate/.

Configuring Log Rotation for Zend Server Logs

The following procedure describes how to configure automatic log rotation for all Zend Server logs, using the logrotate daemon. For full details on the third party logrotate utility, see the utility's man page (man logrotate).

This daemon is installed by default, or can be easily installed on all Zend Server supported Linux distributions.

Before using logrotate, make sure that the Zend component internal log rotation is disabled (see To_Disable_Log_Rotation).

 

 

Instructions on how to complete a procedure

To configure log rotation:

  1. Log in as root or use sudo to execute the following commands.

  2. Create a file called zendserver using a text editor and save it in /etc/logrotate.d/, with the following content:

/usr/local/zend/var/log/*.log {

        size 5M

        missingok

        rotate 10

        compress

        delaycompress

        copytruncate

}

  1. Save the file.

You have now created a configuration file for all the files located in /usr/local/zend/var/log/ that will be picked-up by logrotate. According to the above mentioned configuration, logrotate checks the file size of each log, every time it is executed (through a daily cron job on most systems). If the file size exceeds 5Mb, the log file is archived by moving the content to a new file and truncating the log file. The new file's name is the same name with an additional number added to the file name. According to the example, logrotate created up to ten backup files. After exceeding ten files, the oldest file is deleted and replaced with new content.

The code example describes the following settings:

  • size 5M = file size to rotate
  • missingok = if the file is not found, do not generate an error.
  • rotate 10 = keep up to ten backup files.
  • compress = compress archive log files, using gzip.
  • delaycompress = do not compress the newest file created.
  • copytruncate = rotation method. In this case, copy the content to a new file and truncate the active log.

To Disable Log Rotation

The following procedure describes how to disable Zend component internal log rotation.

 

 

Instructions on how to complete a procedure

To disable log rotation, set the log_rotation_size directive to 0.

The default log rotation directive value is 10mb.

 

 

Related Links

Related Links:

Package Setup and Control Scripts

Ports and Services

Installed Components

Upgrading 

Linux Reference Information for logrotate  - External Link