Yu Watanabe Yu Watanabe - 2 months ago 24x
Ruby Question

Ruby code in logstash failing with _rubyexception

I would like to get help with the code in ruby filter.

logstash version is 5.0.0 alpha4.

I am testing the code in ruby filter as below but I am getting _rubyexception.

ruby {
code => "
event['newfield'] = 'test'

ruby filter is defined inside filter { }.
The logstash.log shows as below,

:timestamp=>"2016-08-03T15:26:47.291000+0900", :message=>"Ruby exception occurred: undefined method[]=' for 2016-08-03T06:26:46.829Z test %{message}:LogStash::Event", :level=>:error}

I cant find the reason why ruby filter is unable to use event object.
I appreciate if I could get some help to cope this issue.


Val Val

There is a new event API in Logstash 5.0.0 and now you need to set fields on the event as follows:

  ruby {
    code => "
      event.set('newfield', 'test')