How to Rotate Log Files in Fluentd?

Better Stack Team
Updated on February 5, 2024

Fluentd offers the capability to set up log rotation, particularly useful when managing large volumes of logs that consume significant disk space. This feature can be configured through Fluentd's system-wide settings.

Here is an example of a log rotation configuration in Fluentd that can rotate logs daily:

    rotate_age 7
    rotate_size 1048576

The configuration options are as follows:

  • rotate_age: This parameter specifies the maximum age of log files in days before they are rotated. In this example, logs older than seven days will be rotated.

  • rotate_size: This option defines the maximum file size in bytes for a log file before it gets rotated. Here, the file size threshold for rotation is set at 1MB.

Additionally, the rotate_age option can accept string values for more dynamic scheduling:

    rotate_age weekly
    rotate_size 1048576

Setting rotate_age to "weekly" means that the files will be rotated every week.

These settings are not limited to configuration files. You can also pass them as command-line arguments:

fluentd -c fluent.conf --log-rotate-age 7 --log-rotate-size 104857600

🔭 Want to centralize and monitor your logs?

Go to Logtail and start your log management in 5 minutes.

Better Uptime Dashboard

Make your mark

Join the writer's program

Are you a developer and love writing and sharing your knowledge with the world? Join our guest writing program and get paid for writing amazing technical guides. We'll get them to the right readers that will appreciate them.

Write for us
Writer of the month
Marin Bezhanov
Marin is a software engineer and architect with a broad range of experience working...
Build on top of Better Stack

Write a script, app or project on top of Better Stack and share it with the world. Make a public repository and share it with us at our email.

or submit a pull request and help us build better products for everyone.

See the full list of amazing projects on github