Class: LogStash::Codecs::Plain

Inherits:
Base
  • Object
show all
Includes:
PluginMixins::EventSupport::EventFactoryAdapter
Defined in:
lib/logstash/codecs/plain.rb

Overview

The “plain” codec is for plain text with no delimiting between events.

This is mainly useful on inputs and outputs that already have a defined framing in their transport protocol (such as zeromq, rabbitmq, redis, etc)

Constant Summary collapse

MESSAGE_FIELD =
"message".freeze

Instance Method Summary collapse

Constructor Details

#initialize(*params) ⇒ Plain

Returns a new instance of Plain.



34
35
36
37
38
39
40
41
# File 'lib/logstash/codecs/plain.rb', line 34

def initialize(*params)
  super

  @original_field = ecs_select[disabled: nil, v1: '[event][original]']

  @converter = LogStash::Util::Charset.new(@charset)
  @converter.logger = @logger
end

Instance Method Details

#decode(data) {|event| ... } ⇒ Object

Yields:

  • (event)


49
50
51
52
53
54
55
# File 'lib/logstash/codecs/plain.rb', line 49

def decode(data)
  message = @converter.convert(data)
  event = event_factory.new_event
  event.set MESSAGE_FIELD, message
  event.set @original_field, message.dup.freeze if @original_field
  yield event
end

#encode(event) ⇒ Object



57
58
59
60
# File 'lib/logstash/codecs/plain.rb', line 57

def encode(event)
  encoded = @format ? event.sprintf(@format) : event.to_s
  @on_event.call(event, encoded)
end

#registerObject



43
44
45
# File 'lib/logstash/codecs/plain.rb', line 43

def register
  # no-op
end