Class: LogStash::Codecs::EDNLines

Inherits:
Base
  • Object
show all
Extended by:
PluginMixins::ValidatorSupport::FieldReferenceValidationAdapter
Includes:
PluginMixins::EventSupport::EventFactoryAdapter
Defined in:
lib/logstash/codecs/edn_lines.rb

Instance Method Summary collapse

Constructor Details

#initialize(params = {}) ⇒ EDNLines

Returns a new instance of EDNLines.



27
28
29
30
# File 'lib/logstash/codecs/edn_lines.rb', line 27

def initialize(params={})
  super(params)
  @lines = LogStash::Codecs::Line.new
end

Instance Method Details

#decode(data) ⇒ Object



33
34
35
36
37
38
39
40
41
42
# File 'lib/logstash/codecs/edn_lines.rb', line 33

def decode(data)
  @lines.decode(data) do |event|
    begin
      yield targeted_event_factory.new_event(EDN.read(event.get("message")))
    rescue => e
      @logger.warn("EDN parse failure. Falling back to plain-text", :error => e, :data => data)
      yield event_factory.new_event("message" => data)
    end
  end
end

#encode(event) ⇒ Object



45
46
47
48
49
50
51
52
# File 'lib/logstash/codecs/edn_lines.rb', line 45

def encode(event)
  # use normalize to make sure returned Hash is pure Ruby for
  # #to_edn which relies on pure Ruby object recognition
  data = LogStash::Util.normalize(event.to_hash)
  # timestamp is serialized as a iso8601 string
  # merge to avoid modifying data which could have side effects if multiple outputs
  @on_event.call(event, data.merge(LogStash::Event::TIMESTAMP => event.timestamp.to_iso8601).to_edn + NL)
end

#registerObject



22
23
24
# File 'lib/logstash/codecs/edn_lines.rb', line 22

def register
  require "edn"
end