Project: APISIX (Orchestration & Management / API Gateway)
File: log-rotate.md

title: log-rotate keywords: Apache APISIX API Gateway Plugin Log rotate description: This document contains information about the Apache APISIX log-rotate Plugin. <!-- --> The `log-rotate` Plugin is used to keep rotating access and error log files in the log directory at regular intervals. You can configure how often the logs are rotated and how many logs to keep. When the number of logs exceeds, older logs are automatically deleted. | Name | Type | Required | Default | Description | |--||-||| | interval | integer | True | 60 * 60 | Time in seconds specifying how often to rotate the logs. | | max_kept | integer | True | 24 * 7 | Maximum number of historical logs to keep. If this number is exceeded, older logs are deleted. | | max_size | integer | False | -1 | Max size(Bytes) of log files to be rotated, size check would be skipped with a value less than 0 or time is up specified by interval. | | enable_compression | boolean | False | false | When set to `true`, compresses the log file (gzip). Requires `tar` to be installed. | To enable the Plugin, add it in your configuration file (`conf/config.yaml`): ```yaml title="conf/config.yaml" plugins: log-rotate plugin_attr: log-rotate: interval: 3600 # rotate interval (unit: second) max_kept: 168 # max number of log files will be kept max_size: -1 # max size of log files will be kept enable_compression: false # enable log file compression(gzip) or not, default false ``` Once you enable the Plugin as shown above, the logs will be stored and rotated based on your configuration. In the example below the `interval` is set to `10` and `max_kept` is set to `10`. This will create logs as shown: ```shell ll logs ``` ```shell total 44K

1 resty resty 0 Mar 20 20:32 2020-03-2020-32-40access.log -rw-r--r--. 1 resty resty 2.4K Mar 20 20:32 2020-03-2020-32-40error.log -rw-r--r--. 1 resty resty 0 Mar 20 20:32 2020-03-2020-32-50access.log -rw-r--r--. 1 resty resty 2.8K Mar 20 20:32 2020-03-2020-32-50error.log -rw-r--r--. 1 resty resty 0 Mar 20 20:32 2020-03-2020-33-00access.log -rw-r--r--. 1 resty resty 2.4K Mar 20 20:33 2020-03-2020-33-00error.log -rw-r--r--. 1 resty resty 0 Mar 20 20:33 2020-03-2020-33-10access.log -rw-r--r--. 1 resty resty 2.4K Mar 20 20:33 2020-03-2020-33-10error.log -rw-r--r--. 1 resty resty 0 Mar 20 20:33 2020-03-2020-33-20access.log -rw-r--r--. 1 resty resty 2.4K Mar 20 20:33 2020-03-2020-33-20error.log -rw-r--r--. 1 resty resty 0 Mar 20 20:33 2020-03-2020-33-30access.log -rw-r--r--. 1 resty resty 2.4K Mar 20 20:33 2020-03-2020-33-30error.log -rw-r--r--. 1 resty resty 0 Mar 20 20:33 2020-03-2020-33-40access.log -rw-r--r--. 1 resty resty 2.8K Mar 20 20:33 2020-03-2020-33-40error.log -rw-r--r--. 1 resty resty 0 Mar 20 20:33 2020-03-2020-33-50access.log -rw-r--r--. 1 resty resty 2.4K Mar 20 20:33 2020-03-2020-33-50error.log -rw-r--r--. 1 resty resty 0 Mar 20 20:33 2020-03-2020-34-00access.log -rw-r--r--. 1 resty resty 2.4K Mar 20 20:34 2020-03-2020-34-00error.log -rw-r--r--. 1 resty resty 0 Mar 20 20:34 2020-03-2020-34-10access.log -rw-r--r--. 1 resty resty 2.4K Mar 20 20:34 2020-03-2020-34-10error.log -rw-r--r--. 1 resty resty 0 Mar 20 20:34 access.log -rw-r--r--. 1 resty resty 1.5K Mar 20 21:31 error.log ``` If you have enabled compression, the logs will be as shown below: ```shell total 10.5K -rw-r--r--. 1 resty resty 1.5K Mar 20 20:33 2020-03-2020-33-50access.log.tar.gz -rw-r--r--. 1 resty resty 1.5K Mar 20 20:33 2020-03-2020-33-50error.log.tar.gz -rw-r--r--. 1 resty resty 1.5K Mar 20 20:33 2020-03-2020-34-00access.log.tar.gz -rw-r--r--. 1 resty resty 1.5K Mar 20 20:34 2020-03-2020-34-00error.log.tar.gz -rw-r--r--. 1 resty resty 1.5K Mar 20 20:34 2020-03-2020-34-10access.log.tar.gz -rw-r--r--. 1 resty resty 1.5K Mar 20 20:34 2020-03-2020-34-10error.log.tar.gz -rw-r--r--. 1 resty resty 0 Mar 20 20:34 access.log -rw-r--r--. 1 resty resty 1.5K Mar 20 21:31 error.log ``` To remove the `log-rotate` Plugin, you can remove it from your configuration file (`conf/config.yaml`): ```yaml title="conf/config.yaml" plugins: ```