> For the complete documentation index, see [llms.txt](https://docs.glesys.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.glesys.com/products/compute/guides-for-server-management/log-rotation-in-linux-systems.md).

# Log rotation in Linux systems

***

This how-to is about rotating log files. Log rotation is useful for many reasons, but most importantly, it organizes logs by date instead of letting a single file grow indefinitely. Additionally, the rotated files are compressed and removed after a predetermined period.

Here you’ll find an example of how the logs can be rotated for a fictional application, `myapp`.

The following should be placed in `/etc/logrotate.d/myapp`.

{% code title="/etc/logrotate.d/myapp" %}

```
/home/myuser/log/myapp/*.log {
       weekly
       missingok
       notifempty
       rotate 20
       compress
       delaycompress
       create 640 myuser mygroup
}
```

{% endcode %}

In the example, we have an application named `myapp` that runs under the user `myuser` and group `mygroup`. The application writes its logs to the directory `/home/myuser/log/myapp`, producing two files there: `info.log` and `error.log`.

From top to bottom, we can see that:

* All log files are rotated weekly.
* Empty files are not rotated.
* If a file is missing, no error message is generated.
* Twenty weeks of history are retained.
* The rotated files are compressed.
* The most recently rotated file is left uncompressed.
* After rotation, a new empty file is created with permissions `640` and ownership `myuser:mygroup`.
