# How to catch errors in output plugin?

**URL:** https://discuss.elastic.co/t/how-to-catch-errors-in-output-plugin/60297
**Category:** Logstash
**Created:** [September 12, 2016, 1:46pm UTC](https://discuss.elastic.co/t/how-to-catch-errors-in-output-plugin/60297 "2016-09-12T13:46:17Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![tiwilliam](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/tiwilliam/32/11867_2.png) [@tiwilliam](https://discuss.elastic.co/u/tiwilliam)
#### Post date: [September 12, 2016, 1:46pm UTC](https://discuss.elastic.co/t/how-to-catch-errors-in-output-plugin/60297/1 "2016-09-12T13:46:17Z")

</div>

Hi,

I'm trying to write a tag or a field in `@metadata` in an output plugin but can't match that value in a if statement.

Here's the output block:

```auto
output {
  something {
    ...setting the tag/field inside this plugin...
  }

  if "_outputfailed" in [tags] {
    statsd {
      increment => ["fail"]
    }
  } else {
    statsd {
      increment => ["success"]
    }
  }
}

```

I can clearly see the tag if I send the event to stdout, same thing with the `@metadata` field, it's there and it's an integer, but I can't match against it. I've also tried to use the value in the statsd increment call like: `fail_%{[@metadata][output_status]}`, that's always set to the expected output status and renders `fail_200`. I've tried matching both strings and integers, exact match and in list matches, nothing works.

Statements I've tested, all failing, value of the `@metadata` field is `200`:

```auto
if "_outputfailed" in [tags]
if [tags] in ["_outputfailed"]
if [@metadata][output_status] == 200
if [@metadata][output_status] == "200"
if [@metadata][output_status] in [200, 201]
if [@metadata][output_status] in ["200", "201"]

```

So my question is, can I set a field or tag in an output plugin and match against it? Or how can I see if my output filter got an error and handle it?

-- William

---

<div class="post-metadata">

### Author: ![krzysztof\_pl](https://avatars.discourse-cdn.com/v4/letter/k/eada6e/32.png) [@krzysztof\_pl](https://discuss.elastic.co/u/krzysztof_pl)
#### Post date: [October 21, 2016, 1:40pm UTC](https://discuss.elastic.co/t/how-to-catch-errors-in-output-plugin/60297/2 "2016-10-21T13:40:25Z")

</div>

hi,  
just to make sure: Do you remember about 'curly braces'?  
I mean: you always have got`if [tags] in ["_outputfailed"] { ... }` ,right?

Did you test config file? Simple syntax test:  
`sudo /opt/logstash/bin/logstash -f /path-to-file/mylogstash.conf --configtest`  
I am not saying that it covers 100% cases, nor detect all errors, but above command  
is really helpful.

---

<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: [July 6, 2017, 4:33am UTC](https://discuss.elastic.co/t/how-to-catch-errors-in-output-plugin/60297/3 "2017-07-06T04:33:16Z")

</div>


