> 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`.


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.glesys.com/products/compute/guides-for-server-management/log-rotation-in-linux-systems.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
