Enable log rotation for edge-router.log

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

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.

In Edge for Private Cloud, some of the main log files on each of the Apigee components are configured with a default rotation mechanism.

For example, on the Router component, the following files are configured with default rotation mechanism:

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

However, there are certain log files in Apigee components that are not configured with default rotation. On the Apigee component Router edge-router.log file is one of those files for which log rotation is not configured by default.

Log rotation can be enabled using different utilities/frameworks like logrotate, logback or log4j. This document explains how to configure log rotation for /opt/apigee/var/log/edge-router/edge-router.log file 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.

Enabling log rotation for edge-router.log on the Router

This section explains how to enable log rotation for /opt/apigee/var/log/edge-router/edge-router.log logs on the Edge Routers.

The following steps describe how to enable log rotation for edge-router.log file.

  1. Open the /opt/apigee/edge-router/logrotate/logrotate.conf file on the Router machine in an editor. If the file does not exist, create it. For example:

    vi /opt/apigee/edge-router/logrotate/logrotate.conf
    
  2. Add a snippet to the file similar to the one shown below:
    /opt/apigee/var/log/edge-router/edge-router.log {
        missingok
        copytruncate
        rotate 5
        size 10M
        compress
        delaycompress
        notifempty
        nocreate
        sharedscripts
        }
  3. Save your changes.
  4. Open 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 -f /opt/apigee/edge-router/logrotate/logrotate.conf
  6. Save the crontab and monitor log rotation during the next run of cron job.

Verifying log rotation for edge-router.log on the Router

  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-router.log file.
  2. Navigate to the /opt/apigee/var/log/edge-router/ directory and verify that the edge-router.log file is rotated.

    Sample listing of log files:

    ls -ltrh | grep 'edge-router'
    
    -rw-r--r--. 1 apigee apigee 6.0K Feb 16 00:00 edge-router.log.1.gz
    -rw-r--r--. 1 apigee apigee 3.0K Feb 16 01:23 edge-router.log

    The above output indicates that the edge-router.log files are rotated and saved as GZ files.

  3. If you don’t see the edge-router.log files are being rotated, then verify that you have followed all the steps outlined in Enabling log rotation for edge-router.log on the Router 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, contact Apigee Edge Support.