Method: LogStash::Codecs::Fluent#encode

Defined in:
lib/logstash/codecs/fluent.rb

#encode(event) ⇒ Object

def decode



66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
# File 'lib/logstash/codecs/fluent.rb', line 66

def encode(event)
  # Ensure tag to "tag1.tag2.tag3" style string.
  # Fluentd cannot handle Array class value in forward protocol's tag.
  tag = forwardable_tag(event)
  epochtime = if @nanosecond_precision
                EventTime.new(event.timestamp.to_i, event.timestamp.usec * 1000)
              else
                event.timestamp.to_i
              end

  # use normalize to make sure returned Hash is pure Ruby for
  # MessagePack#pack which relies on pure Ruby object recognition
  data = LogStash::Util.normalize(event.to_hash)

  @packer.clear
  @on_event.call(event, @packer.pack([tag, epochtime, normalize_timestamps(data)]))
end