Enable log rotation for edge-message-processor.log

You're viewing Apigee Edge documentation.
Go to the Apigee X documentation.
info

Log rotation—the process of rotating multiple log files in and out of use— simplifies administration of systems that generate large numbers of log files. Log rotation enables automatic rotation, compression, removal, and mailing of log files.

In Edge for Private Cloud, some of the main log files on each apigee component are configured with a default rotation mechanism. For example, on the Message Processor component, the following files are configured with a default rotation mechanism using logback:

  • /opt/apigee/var/log/edge-message-processor/logs/system.log
  • /opt/apigee/var/log/edge-message-processor/logs/events.log
  • /opt/apigee/var/log/edge-message-processor/logs/startupruntimeerrors.log
  • /opt/apigee/var/log/edge-message-processor/logs/configurations.log
  • /opt/apigee/var/log/edge-message-processor/logs/transactions.log

Similar files exist for other edge-* components (whose names begin with edge-), such as edge-management-server, edge-router, edge-postgres-server, and edge-qpid-server.

Each of these edge-* components also generate an additional log file that is a redirected output of the respective component's console. In the case of the Message Processor component, this file is called /opt/apigee/var/log/edge-message-processor/edge-message-processor.log. Other edge-* components generate a similar file. These files' rotation are not done by the logback library, but rather using logrotate and crontab.

Before you begin

  • If you aren't familiar with logrotate configurations, read the logrotate manual.
  • If you aren't familiar with crontab configurations, read the crontab manual.

Enable log rotation

This section applies to Edge for Private Cloud versions 4.50.00 and 4.51.00.

Log rotation is a mechanism which is designed to ease administration of systems that generate large numbers of log files. It allows automatic rotation, compression, removal and mailing of log files.

By default, some of the main log files on each of the apigee components are configured with a default rotation mechanism. For example, on the Message Processor component, the following files are configured with default rotation mechanism:

  • /opt/apigee/var/log/edge-message-processor/logs/system.log
  • /opt/apigee/var/log/edge-message-processor/logs/events.log
  • /opt/apigee/var/log/edge-message-processor/logs/startupruntimeerrors.log
  • /opt/apigee/var/log/edge-message-processor/logs/configurations.log
  • /opt/apigee/var/log/edge-message-processor/logs/transactions.log

However, other log files in apigee components are not configured with default rotation. For example, log rotation is not configured by default on the apigee component Message Processor file edge-message-processor.log.

Log rotation can be enabled using different utilities/frameworks such as logrotate, logback, or log4j. This section explains how to configure log rotation for /opt/apigee/var/log/edge-message-processor/edge-message-processor.log file using logrotate and crontab.

Enabling log rotation for edge-message-processor.log on Message Processors

This section explains how to enable log rotation for /opt/apigee/var/log/edge-message- processor/edge-message-processor.log logs on the Edge Message Processors.

The following steps describe how to enable log rotation for edge-message-processor.log file:

  1. Open the /opt/apigee/edge-message-processor/logrotate/logrotate.conf file on the Message Processor machine in an editor. If the file does not exist, create it. For example:
    vi /opt/apigee/edge-message-processor/logrotate/logrotate.conf
    
  2. Add a snippet to the file similar to the one shown below:
    /opt/apigee/var/log/edge-message-processor/edge-message-processor.log {
        missingok
        copytruncate
        rotate 5
        size 10M
        compress
        delaycompress
        notifempty
        nocreate
        sharedscripts
        }
    
  3. Save your changes.
  4. Open the apigee user's crontab using the following command:
    sudo crontab -u apigee -e
    
  5. Add the following cron job to the apigee user's crontab :
    0 0 * * * nice -n 19 ionice -c3 /usr/sbin/logrotate -s /opt/apigee/var/run/edge-message-processor/logrotate.status -f /opt/apigee/edge-message-processor/logrotate/logrotate.conf
    
  6. Save the crontab and monitor log rotation during the next run of cron job.

Verifying log rotation for edge-message-processor.log on the Message Processor

  1. Once the scheduled cron job runs, the log file will be rotated. From the above example, cron job is scheduled to run every day at 00:00 AM to rotate the edge-message- processor.log file.
  2. Navigate to the /opt/apigee/var/log/edge-message-processor/ directory and verify that the edge-message-processor.log file is rotated.

    Sample listing of log files

    ls -ltrh | grep 'edge-message-processor'
    
    -rw-r--r--. 1 apigee apigee  17K Feb  7 00:00 edge-message-processor.log.1.gz
    -rw-r--r--. 1 apigee apigee 5.3K Feb  7 09:12 edge-message-processor.log
    

    The above output indicates that the edge-message-processor.log files are rotated and saved as a GZ file.

  3. If you don't see the edge-message-processor.log files are being rotated, then verify that you have followed all the steps outlined in Enabling log rotation for edge-message-processor.log on Message Processors correctly. If you have missed any step, repeat all the steps again correctly.
  4. If you are still not able to get the log rotation working, then contact Apigee Edge Support.