# Elasticsearch and Logstash logs retention to 7 days

**URL:** <https://discuss.elastic.co/t/elasticsearch-and-logstash-logs-retention-to-7-days/259464>\
**Category:** Elasticsearch\
**Created:** [December 23, 2020, 9:51am UTC](https://discuss.elastic.co/t/elasticsearch-and-logstash-logs-retention-to-7-days/259464 "2020-12-23T09:51:38Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![atharvak](https://avatars.discourse-cdn.com/v4/letter/a/7ab992/32.png) [@atharvak](https://discuss.elastic.co/u/atharvak)\
**Post date:** [December 23, 2020, 9:51am UTC](https://discuss.elastic.co/t/elasticsearch-and-logstash-logs-retention-to-7-days/259464/1 "2020-12-23T09:51:38Z")

</div>

Hi guys,  
Is there any way to reduce the Elasticsearch and logstash app logs count to 7 days using `log4j.properties`? Currently as I can observe, the log rotation in `/var/log/elasticsearch` and `/var/log/logstash` has no limit and goes on rolling over. I want only previous 7 backed-up log files on system.  
Any help is appreciated. Thank you.

---

<div class="post-metadata">

**Author:** ![AClerk](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/aclerk/32/55297_2.png) [@AClerk](https://discuss.elastic.co/u/AClerk)\
**Post date:** [December 23, 2020, 11:42pm UTC](https://discuss.elastic.co/t/elasticsearch-and-logstash-logs-retention-to-7-days/259464/2 "2020-12-23T23:42:12Z")

</div>

with elasticsearch, please read the following

> **[Logging | Elasticsearch Guide \[master\] | Elastic](https://www.elastic.co/guide/en/elasticsearch/reference/master/logging.html)**

> If you want to retain log files for a specified period of time, you can use a rollover strategy with a delete action.

```auto
appender.rolling.strategy.type = DefaultRolloverStrategy 
appender.rolling.strategy.action.type = Delete 
appender.rolling.strategy.action.basepath = ${sys:es.logs.base_path} 
appender.rolling.strategy.action.condition.type = IfFileName 
appender.rolling.strategy.action.condition.glob = ${sys:es.logs.cluster_name}-* 
appender.rolling.strategy.action.condition.nested_condition.type = IfLastModified 
appender.rolling.strategy.action.condition.nested_condition.age = 7D 

```

> 1. Configure the DefaultRolloverStrategy
> 2. Configure the Delete action for handling rollovers
> 3. The base path to the Elasticsearch logs
> 4. The condition to apply when handling rollovers
> 5. Delete files from the base path matching the glob ${sys:es.logs.cluster\_name}-\*; this is the glob that log files are rolled to; this is needed to only delete the rolled Elasticsearch logs but not also delete the deprecation and slow logs
> 6. A nested condition to apply to files matching the glob
> 7. Retain logs for seven days

Cheers!

---

<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:** [January 20, 2021, 11:42pm UTC](https://discuss.elastic.co/t/elasticsearch-and-logstash-logs-retention-to-7-days/259464/3 "2021-01-20T23:42:19Z")

</div>

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