# File output plugin's file rotation based on size or say after every 4 hours

**URL:** <https://discuss.elastic.co/t/file-output-plugins-file-rotation-based-on-size-or-say-after-every-4-hours/119369>\
**Category:** Logstash\
**Created:** [February 11, 2018, 6:57am UTC](https://discuss.elastic.co/t/file-output-plugins-file-rotation-based-on-size-or-say-after-every-4-hours/119369 "2018-02-11T06:57:48Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Arvind\_Kumar1988](https://avatars.discourse-cdn.com/v4/letter/a/c5a1d2/32.png) [@Arvind\_Kumar1988](https://discuss.elastic.co/u/Arvind_Kumar1988)\
**Post date:** [February 11, 2018, 6:57am UTC](https://discuss.elastic.co/t/file-output-plugins-file-rotation-based-on-size-or-say-after-every-4-hours/119369/1 "2018-02-11T06:57:48Z")

</div>

I am using file output plugin to write the logs processed by Logstash to files which are rotated day-wise but I want rotation of the output files based on the file size or after every say 4 hours. How can I achieve this?

---

<div class="post-metadata">

**Author:** ![magnusbaeck](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/magnusbaeck/32/44943_2.png) [@magnusbaeck](https://discuss.elastic.co/u/magnusbaeck)\
**Post date:** [February 13, 2018, 9:26pm UTC](https://discuss.elastic.co/t/file-output-plugins-file-rotation-based-on-size-or-say-after-every-4-hours/119369/2 "2018-02-13T21:26:28Z")

</div>

You can use a ruby filter to create a field (as a subfield of `@metadata` if you don't want the field to be visible to the outputs) containing a value that you use in the `path` option of your file output. For example, to rotate logs every four hours you could take the current hour (in the range 0 to 23, obviously) and divide it with four to get an integer in the range 0 to 5.

---

<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:** [March 13, 2018, 9:26pm UTC](https://discuss.elastic.co/t/file-output-plugins-file-rotation-based-on-size-or-say-after-every-4-hours/119369/3 "2018-03-13T21:26:33Z")

</div>

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