Class: LogStash::Codecs::EDNLines

Inherits:
Base
  • Object
show all
Defined in:
lib/logstash/codecs/edn_lines.rb

Instance Method Summary collapse

Constructor Details

#initialize(params = {}) ⇒ EDNLines

Returns a new instance of EDNLines.



14
15
16
17
# File 'lib/logstash/codecs/edn_lines.rb', line 14

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

Instance Method Details

#decode(data) ⇒ Object



20
21
22
23
24
25
26
27
28
29
# File 'lib/logstash/codecs/edn_lines.rb', line 20

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

#encode(event) ⇒ Object



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

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



9
10
11
# File 'lib/logstash/codecs/edn_lines.rb', line 9

def register
  require "edn"
end