# How to print events and fields in Logstash using Ruby code?

**URL:** <https://discuss.elastic.co/t/how-to-print-events-and-fields-in-logstash-using-ruby-code/185305>\
**Category:** Logstash\
**Created:** [June 12, 2019, 1:06am UTC](https://discuss.elastic.co/t/how-to-print-events-and-fields-in-logstash-using-ruby-code/185305 "2019-06-12T01:06:37Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![EZprogramming](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/ezprogramming/32/57291_2.png) [@EZprogramming](https://discuss.elastic.co/u/EZprogramming)\
**Post date:** [June 12, 2019, 1:06am UTC](https://discuss.elastic.co/t/how-to-print-events-and-fields-in-logstash-using-ruby-code/185305/1 "2019-06-12T01:06:37Z")

</div>

Is there anyway I can print the events with ruby in Logstash?

**Logstash.conf file:**

```
input {
    http {
        port => 9600
        id => "my_plugin_id"
    }
}

filter {
    ruby {
        code => "puts event['message']"
    }
}

output{
    stdout { 
        codec => rubydebug {
            metadata => true
        }
    }
}

```

**Error:**

> [2019-06-11T17:59:05,893][ERROR][logstash.filters.ruby] Ruby exception occurred: undefined method `' for #LogStash::Event:0x642b9c0d

---

<div class="post-metadata">

**Author:** ![shin-higuchi](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/shin-higuchi/32/46524_2.png) [@shin-higuchi](https://discuss.elastic.co/u/shin-higuchi)\
**Post date:** [June 12, 2019, 2:22am UTC](https://discuss.elastic.co/t/how-to-print-events-and-fields-in-logstash-using-ruby-code/185305/2 "2019-06-12T02:22:19Z")

</div>

Hi,

You can do it with

puts event.get('fieldName')

---

<div class="post-metadata">

**Author:** ![EZprogramming](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/ezprogramming/32/57291_2.png) [@EZprogramming](https://discuss.elastic.co/u/EZprogramming)\
**Post date:** [June 12, 2019, 2:34pm UTC](https://discuss.elastic.co/t/how-to-print-events-and-fields-in-logstash-using-ruby-code/185305/3 "2019-06-12T14:34:33Z")

</div>

Yes, that worked, except fieldname needs to be in strings " ", and not ' '. Thanks for your help @shin-higuchi! 🙂

**Solution:**

```
filter {
    ruby {
        code => 'puts event.get("message")'
    }
}

```

or

```
filter {
    ruby {
        code => 'puts event.get("[message]")'
    }
}
```

---

<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 10, 2019, 2:34pm UTC](https://discuss.elastic.co/t/how-to-print-events-and-fields-in-logstash-using-ruby-code/185305/4 "2019-07-10T14:34:47Z")

</div>

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