# Conditional file output with overwrite leads to empty file

**URL:** <https://discuss.elastic.co/t/conditional-file-output-with-overwrite-leads-to-empty-file/233198>\
**Category:** Logstash\
**Created:** [May 18, 2020, 8:46pm UTC](https://discuss.elastic.co/t/conditional-file-output-with-overwrite-leads-to-empty-file/233198 "2020-05-18T20:46:05Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![nicklan](https://avatars.discourse-cdn.com/v4/letter/n/13edae/32.png) [@nicklan](https://discuss.elastic.co/u/nicklan)\
**Post date:** [May 18, 2020, 8:46pm UTC](https://discuss.elastic.co/t/conditional-file-output-with-overwrite-leads-to-empty-file/233198/1 "2020-05-18T20:46:05Z")

</div>

I have a file output that is triggered conditionally set up as:

```auto
output {
  if [@metadata][dofile] {
    file {
      path => "/tmp/ts.out"
      codec => line { format => "%{[afield]}"}
      write_behavior => "overwrite"
    }
  }
  ...
}

```

This works sometimes, but what I observe is that most of the time the file is empty. It seems that if the conditional doesn't match the file is just truncated. If I `tail -f` the file I see all the expected data, but doing a cat at random points almost never shows things.

help! 🙂

---

<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:** [June 15, 2020, 8:46pm UTC](https://discuss.elastic.co/t/conditional-file-output-with-overwrite-leads-to-empty-file/233198/2 "2020-06-15T20:46:05Z")

</div>

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