# Implementing Event dependent configurations using Java output plugins

**URL:** <https://discuss.elastic.co/t/implementing-event-dependent-configurations-using-java-output-plugins/195780>\
**Category:** Logstash\
**Created:** [August 19, 2019, 4:30pm UTC](https://discuss.elastic.co/t/implementing-event-dependent-configurations-using-java-output-plugins/195780 "2019-08-19T16:30:05Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Xucito](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/xucito/32/45111_2.png) [@Xucito](https://discuss.elastic.co/u/Xucito)\
**Post date:** [August 19, 2019, 4:30pm UTC](https://discuss.elastic.co/t/implementing-event-dependent-configurations-using-java-output-plugins/195780/1 "2019-08-19T16:30:05Z")

</div>

Following from the issue below:

> <https://github.com/logstash-plugins/logstash-output-java_output_example/issues/6>

I am looking to access configurations that are evaluated based on the event

[https://www.elastic.co/guide/en/logstash/current/event-dependent-configuration.html](https://www.elastic.co/guide/en/logstash/current/event-dependent-configuration.html)

```
output {
  file {
    path => "<changed value per event>"
  }
}

```

An example of usage is the configuration above. How would you configure and access it in your output function within your Plugin class.

---

<div class="post-metadata">

**Author:** ![Xucito](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/xucito/32/45111_2.png) [@Xucito](https://discuss.elastic.co/u/Xucito)\
**Post date:** [August 19, 2019, 4:30pm UTC](https://discuss.elastic.co/t/implementing-event-dependent-configurations-using-java-output-plugins/195780/2 "2019-08-19T16:30:37Z")

</div>

@danhermann

---

<div class="post-metadata">

**Author:** ![danhermann](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/danhermann/32/33024_2.png) [@danhermann](https://discuss.elastic.co/u/danhermann)\
**Post date:** [August 19, 2019, 5:10pm UTC](https://discuss.elastic.co/t/implementing-event-dependent-configurations-using-java-output-plugins/195780/3 "2019-08-19T17:10:22Z")

</div>

@Xucito, let's say you set `path` to something like `/path/to/my/file/log-%{type}`. In that scenario, you'd expect that events coming through with types of `error`, `warn`, and `info` would be written to the files `log-error`, `log-warn`, and `log-info`, respectively. Inside the plugin's `output()` method, you'd have to retrieve the value of each event's `type` field, check if the currently-open file matched that name and if not, open or create a file with the proper name before writing to it.

Of course, if there were a large number of different values in the event's `type` field, you could end up creating lots of different files which would probably not be ideal.

---

<div class="post-metadata">

**Author:** ![Xucito](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/xucito/32/45111_2.png) [@Xucito](https://discuss.elastic.co/u/Xucito)\
**Post date:** [August 19, 2019, 5:49pm UTC](https://discuss.elastic.co/t/implementing-event-dependent-configurations-using-java-output-plugins/195780/4 "2019-08-19T17:49:09Z")

</div>

> [@danhermann](#):
>
> Inside the plugin's `output()` method, you'd have to retrieve the value of each event's `type` field

I see, so the configuration itself is still only set during initialization however it will contain the instructions of where in the event object to look. The approach would be that one of fields contains the actual payload you may want to send and the other fields would contain the configuration values.

i.e. in syslog output plugin, the message field is assumed to be the actual payload

> **[Syslog output plugin | Logstash Reference \[8.11\] | Elastic](https://www.elastic.co/guide/en/logstash/current/plugins-outputs-syslog.html)**

Thanks for your help

---

<div class="post-metadata">

**Author:** ![danhermann](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/danhermann/32/33024_2.png) [@danhermann](https://discuss.elastic.co/u/danhermann)\
**Post date:** [August 19, 2019, 6:05pm UTC](https://discuss.elastic.co/t/implementing-event-dependent-configurations-using-java-output-plugins/195780/5 "2019-08-19T18:05:56Z")

</div>

> [@Xucito](#):
>
> The approach would be that one of fields contains the actual payload you may want to send and the other fields would contain the configuration values.

Ah, I see now what you were asking. Yes, your above statement is correct and that's the way per-event configuration values work.

---

<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:** [September 16, 2019, 6:06pm UTC](https://discuss.elastic.co/t/implementing-event-dependent-configurations-using-java-output-plugins/195780/6 "2019-09-16T18:06:05Z")

</div>

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