Class: LogStash::Codecs::EDNLines
- Inherits:
-
Base
- Object
- Base
- LogStash::Codecs::EDNLines
- Extended by:
- PluginMixins::ValidatorSupport::FieldReferenceValidationAdapter
- Includes:
- PluginMixins::EventSupport::EventFactoryAdapter
- Defined in:
- lib/logstash/codecs/edn_lines.rb
Instance Method Summary collapse
- #decode(data) ⇒ Object
- #encode(event) ⇒ Object
-
#initialize(params = {}) ⇒ EDNLines
constructor
A new instance of EDNLines.
- #register ⇒ Object
Constructor Details
#initialize(params = {}) ⇒ EDNLines
Returns a new instance of EDNLines.
34 35 36 37 |
# File 'lib/logstash/codecs/edn_lines.rb', line 34 def initialize(params={}) super(params) @lines = LogStash::Codecs::Line.new end |
Instance Method Details
#decode(data) ⇒ Object
40 41 42 43 44 45 46 47 48 49 |
# File 'lib/logstash/codecs/edn_lines.rb', line 40 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
52 53 54 55 56 57 58 59 |
# File 'lib/logstash/codecs/edn_lines.rb', line 52 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..to_iso8601).to_edn + NL) end |
#register ⇒ Object
29 30 31 |
# File 'lib/logstash/codecs/edn_lines.rb', line 29 def register require "edn" end |