dwbutler / logstash-logger

Ruby logger that writes logstash events
MIT License
456 stars 118 forks source link

Instantiate custom formatter classes with customize_event keyword arg #155

Open bcharna opened 4 years ago

bcharna commented 4 years ago

In my application, I want to be able to build a formatter that inherits from LogStashLogger::Formatter::Base to get its overall behavior, and also specifically want to take advantage of the customize_event functionality in that class. So I want to create a class like the following, for example:

class MyFormatter < LogStashLogger::Formatter::Base
  private

  def format_event(event)
    # mutate event here...
    "#{event.to_json}\n"
  end
end

As is, this is not possible because LogStashLogger::Formatter.build_formatter does not pass in customize_event to the initializer of custom formatter classes even when they accept that keyword arg.

bcharna commented 4 years ago

It looks like there are several issues in CI, seemingly unrelated to this change. If this change looks okay, I can attempt to look into the failures.