# How to rotate elastic log files using logrotate instead of log4j

**URL:** <https://discuss.elastic.co/t/how-to-rotate-elastic-log-files-using-logrotate-instead-of-log4j/205210>\
**Category:** Elasticsearch\
**Created:** [October 25, 2019, 8:49am UTC](https://discuss.elastic.co/t/how-to-rotate-elastic-log-files-using-logrotate-instead-of-log4j/205210 "2019-10-25T08:49:19Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![nicolai](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/nicolai/32/55008_2.png) [@nicolai](https://discuss.elastic.co/u/nicolai)\
**Post date:** [October 25, 2019, 8:49am UTC](https://discuss.elastic.co/t/how-to-rotate-elastic-log-files-using-logrotate-instead-of-log4j/205210/1 "2019-10-25T08:49:19Z")

</div>

Hi,

This is to answer a question I've been working on this morning and found no good answers for using google.

We put our logs into a cloud log solution. We're using a collection agent (fluentd) to slurp all files matching `/var/log/**/*.log` and use logrotate(8) for the rotation and deletion after one day. This is convenient and also ensures part of our GDPR compliance: we don't keep log files around and retention and access to the files are managed in the cloud (sorry, not elk).

Changing all instances of `RollingFile` to `File` in the supplied `log4j2.properties` file stops log4j from rotating the files. Writing a logrotate configuration is relatively easy. As far as I can tell you should use the `copytruncate` option when rotating the files.

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [November 22, 2019, 8:49am UTC](https://discuss.elastic.co/t/how-to-rotate-elastic-log-files-using-logrotate-instead-of-log4j/205210/2 "2019-11-22T08:49:21Z")

</div>

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.
