Class: LogStash::Codecs::EDNLines

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

Constant Summary

Constants included from LogStash::Config::Mixin

LogStash::Config::Mixin::CONFIGSORT

Instance Attribute Summary

Attributes included from LogStash::Config::Mixin

#config, #original_params

Attributes inherited from Plugin

#logger, #params

Instance Method Summary collapse

Methods inherited from Base

#clone, #flush, #on_event, #teardown

Methods included from LogStash::Config::Mixin

#config_init, included

Methods inherited from Plugin

#eql?, #finished, #finished?, #hash, #inspect, lookup, #reload, #running?, #shutdown, #teardown, #terminating?, #to_s

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["message"]))
    rescue => e
      @logger.info("EDN parse failure. Falling back to plain-text", :error => e, :data => data)
      yield LogStash::Event.new("message" => data)
    end
  end
end

#encode(data) ⇒ Object



32
33
34
# File 'lib/logstash/codecs/edn_lines.rb', line 32

def encode(data)
  @on_event.call(data.to_hash.to_edn + "\n")
end

#registerObject



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

def register
  require "edn"
end