# Logging from within Ruby Filter

**URL:** https://discuss.elastic.co/t/logging-from-within-ruby-filter/127983
**Category:** Logstash
**Created:** [April 13, 2018, 1:27pm UTC](https://discuss.elastic.co/t/logging-from-within-ruby-filter/127983 "2018-04-13T13:27:04Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![Shaoranlaos](https://avatars.discourse-cdn.com/v4/letter/s/c57346/32.png) [@Shaoranlaos](https://discuss.elastic.co/u/Shaoranlaos)
#### Post date: [April 13, 2018, 1:27pm UTC](https://discuss.elastic.co/t/logging-from-within-ruby-filter/127983/1 "2018-04-13T13:27:04Z")

</div>

Hello,

is it possible to write to the logfile of Logstash from within the Rubyfilter?  
And when yes how?

Thanks in advance

---

<div class="post-metadata">

### Author: ![Shaoranlaos](https://avatars.discourse-cdn.com/v4/letter/s/c57346/32.png) [@Shaoranlaos](https://discuss.elastic.co/u/Shaoranlaos)
#### Post date: [April 18, 2018, 6:35am UTC](https://discuss.elastic.co/t/logging-from-within-ruby-filter/127983/2 "2018-04-18T06:35:31Z")

</div>

I have solved my Problem with a online ruby interpreter and a self written mock for event

but my question still stands, is it possible to log to the logstash log file from within the ruby filter code?

---

<div class="post-metadata">

### Author: ![guyboertje](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/guyboertje/32/31592_2.png) [@guyboertje](https://discuss.elastic.co/u/guyboertje)
#### Post date: [April 18, 2018, 8:44am UTC](https://discuss.elastic.co/t/logging-from-within-ruby-filter/127983/3 "2018-04-18T08:44:23Z")

</div>

You can!!

```auto
  ruby {
    code => '
      event.set("[file-suffix]", event.get("[file-suffix]") + 5.5)
      logger.info("the file-suffix is:", "value" => event.get("[file-suffix]"))
    '
  }

```

logs this

```auto
[2018-04-18T09:34:55,590][INFO][logstash.filters.ruby] the file-suffix is: {"value"=>13.5}

```

you can use `logger.error()`, `logger.warn()`, `logger.info()`, `logger.debug()`, `logger.trace()`  
Each of these methods has the same arguments `<string>`, `<hash>` (optional)  
The hash is written as `<string> => <any object>`. You do not need to wrap the hash argument in the Ruby {} bracket although you can if you want.

---

<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: [May 16, 2018, 8:44am UTC](https://discuss.elastic.co/t/logging-from-within-ruby-filter/127983/4 "2018-05-16T08:44:31Z")

</div>

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