Class: LogStash::Codecs::Msgpack
- Defined in:
- lib/logstash/codecs/msgpack.rb
Constant Summary
Constants included from LogStash::Config::Mixin
LogStash::Config::Mixin::CONFIGSORT
Instance Attribute Summary
Attributes included from LogStash::Config::Mixin
Attributes inherited from Plugin
Instance Method Summary collapse
Methods inherited from Base
#clone, #flush, #initialize, #on_event, #teardown
Methods included from LogStash::Config::Mixin
Methods inherited from Plugin
#eql?, #finished, #finished?, #hash, #initialize, #inspect, lookup, #reload, #running?, #shutdown, #teardown, #terminating?, #to_s
Constructor Details
This class inherits a constructor from LogStash::Codecs::Base
Instance Method Details
#decode(data) {|event| ... } ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/logstash/codecs/msgpack.rb', line 17 def decode(data) begin # Msgpack does not care about UTF-8 event = LogStash::Event.new(MessagePack.unpack(data)) event["@timestamp"] = Time.at(event["@timestamp"]).utc if event["@timestamp"].is_a? Float event["tags"] ||= [] if @format event["message"] ||= event.sprintf(@format) end rescue => e # Treat as plain text and try to do the best we can with it? @logger.warn("Trouble parsing msgpack input, falling back to plain text", :input => data, :exception => e) event["message"] = data event["tags"] ||= [] event["tags"] << "_msgpackparsefailure" end yield event end |
#encode(event) ⇒ Object
38 39 40 41 |
# File 'lib/logstash/codecs/msgpack.rb', line 38 def encode(event) event["@timestamp"] = event["@timestamp"].to_f @on_event.call event.to_hash.to_msgpack end |
#register ⇒ Object
12 13 14 |
# File 'lib/logstash/codecs/msgpack.rb', line 12 def register require "msgpack" end |