# Delete Elasticsearch logs

**URL:** <https://discuss.elastic.co/t/delete-elasticsearch-logs/256639>\
**Category:** Elasticsearch\
**Created:** [November 25, 2020, 10:57am UTC](https://discuss.elastic.co/t/delete-elasticsearch-logs/256639 "2020-11-25T10:57:48Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![hzarrabi](https://avatars.discourse-cdn.com/v4/letter/h/f9ae1b/32.png) [@hzarrabi](https://discuss.elastic.co/u/hzarrabi)\
**Post date:** [November 25, 2020, 10:57am UTC](https://discuss.elastic.co/t/delete-elasticsearch-logs/256639/1 "2020-11-25T10:57:48Z")

</div>

Hi guys,

I would like to delete **elasticsearch logs** placed in **/var/log/elasticsearch** older then 7 days.  
I can not find any parameter in log4j2.properties from ELastic official site.  
Do you have any idea about it or should I use **logrotator** of linux.

Thanks,

---

<div class="post-metadata">

**Author:** ![ropc](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/ropc/32/47022_2.png) [@ropc](https://discuss.elastic.co/u/ropc)\
**Post date:** [November 26, 2020, 6:34am UTC](https://discuss.elastic.co/t/delete-elasticsearch-logs/256639/2 "2020-11-26T06:34:37Z")

</div>

Hi @hzarrabi - I have not tried this but I believe you should be able to able to configure a `Delete` [action](https://logging.apache.org/log4j/2.x/manual/appenders.html#Log_Archive_Retention_Policy:_Delete_on_Rollover) that uses a `IfLastModified` [condition](https://logging.apache.org/log4j/2.x/manual/appenders.html#DeleteIfLastModified).

---

<div class="post-metadata">

**Author:** ![hzarrabi](https://avatars.discourse-cdn.com/v4/letter/h/f9ae1b/32.png) [@hzarrabi](https://discuss.elastic.co/u/hzarrabi)\
**Post date:** [November 29, 2020, 6:44pm UTC](https://discuss.elastic.co/t/delete-elasticsearch-logs/256639/3 "2020-11-29T18:44:20Z")

</div>

Hi @ropc,

Thank you so much. The solution you give, is it applicable to the latest 7.x versions ?

The link **IfLastModified** [condition](https://logging.apache.org/log4j/2.x/manual/appenders.html#Log_Archive_Retention_Policy:_Delete_on_Rollover), shows the following lines which relate to DELETING the log files. But, I don't see them in the log4j2.properties file of recent version 7.x.

```auto
appender.rolling.strategy.action.condition.type = IfFileName
appender.rolling.strategy.action.condition.glob = mylog-*.log
appender.rolling.strategy.action.PathConditions.type = IfAny
appender.rolling.strategy.action.PathConditions.nestedConditions.type = IfLastModified
appender.rolling.strategy.action.PathConditions.nestedConditions.age = 90D

```

Best Regards

---

<div class="post-metadata">

**Author:** ![ropc](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/ropc/32/47022_2.png) [@ropc](https://discuss.elastic.co/u/ropc)\
**Post date:** [November 30, 2020, 12:55am UTC](https://discuss.elastic.co/t/delete-elasticsearch-logs/256639/4 "2020-11-30T00:55:51Z")

</div>

Hi @hzarrabi - yes it is applicable to version 7.x. You will need to amend the `log4j2.properties` configuration file accordingly.

---

<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:** [December 28, 2020, 12:56am UTC](https://discuss.elastic.co/t/delete-elasticsearch-logs/256639/5 "2020-12-28T00:56:02Z")

</div>

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