Logging from within Ruby Filter

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