Logging from within Ruby Filter

Hello,

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

Thanks in advance

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?

You can!!

  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

[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.

5 Likes

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