Class: LogStash::Codecs::Transit
- Inherits:
-
Base
- Object
- Base
- LogStash::Codecs::Transit
- Defined in:
- lib/logstash/codecs/transit.rb
Instance Method Summary collapse
Instance Method Details
#decode(data) {|event| ... } ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/logstash/codecs/transit.rb', line 21 def decode(data) begin data = Base64.decode64(data) if @base64 io = StringIO.new data reader = Transit::Reader.new(@transport.to_sym, io) event = LogStash::Event.new(reader.read) event["tags"] ||= [] rescue => e @logger.warn("Trouble parsing transit input, falling back to plain text", :input => data, :exception => e) event = LogStash::Event.new("") unless event event["message"] = data event["tags"] ||= [] event["tags"] << "_transitparsefailure" end yield event end |
#encode(event) ⇒ Object
40 41 42 43 44 45 46 47 48 49 |
# File 'lib/logstash/codecs/transit.rb', line 40 def encode(event) data = LogStash::Util.normalize(event.to_hash) io = StringIO.new writer = Transit::Writer.new(@transport.to_sym, io) writer.write(data.merge(LogStash::Event::TIMESTAMP => event..to_iso8601)) encoded = io.string encoded = Base64.encode64(encoded) if @base64 @on_event.call(event, encoded) end |
#register ⇒ Object
15 16 17 18 |
# File 'lib/logstash/codecs/transit.rb', line 15 def register require "transit" require "base64" if @base64 end |