Class: LogStash::Codecs::Base
- Includes:
- LogStash::Config::Mixin
- Defined in:
- lib/logstash/codecs/base.rb
Constant Summary
Constants included from LogStash::Config::Mixin
LogStash::Config::Mixin::PLUGIN_VERSION_0_9_0, LogStash::Config::Mixin::PLUGIN_VERSION_1_0_0
Constants included from Util::EnvironmentVariables
Util::EnvironmentVariables::ENV_PLACEHOLDER_REGEX
Constants inherited from Plugin
Instance Attribute Summary
Attributes included from LogStash::Config::Mixin
Attributes inherited from Plugin
Class Method Summary collapse
Instance Method Summary collapse
- #clone ⇒ Object
- #close ⇒ Object
- #decode(data) ⇒ Object (also: #<<)
-
#encode(event) ⇒ Object
DEPRECATED: Prefer defining encode_sync or multi_encode.
- #flush(&block) ⇒ Object
-
#initialize(params = {}) ⇒ Base
constructor
A new instance of Base.
-
#multi_encode(events) ⇒ Object
Relies on the codec being synchronous (which they all are!) We need a better long term design here, but this is an improvement over the current API for shared plugins It is best if the codec implements this directly.
- #on_event(&block) ⇒ Object
- #setup_multi_encode! ⇒ Object
Methods included from LogStash::Config::Mixin
Methods included from Util::EnvironmentVariables
#deep_replace, #replace_env_placeholders
Methods inherited from Plugin
#config_name, #debug_info, #do_close, #eql?, #hash, #id, #inspect, lookup, #metric, #metric=, #reloadable?, reloadable?, #to_s
Methods included from Util::Loggable
included, #logger, #slow_logger
Constructor Details
#initialize(params = {}) ⇒ Base
Returns a new instance of Base.
17 18 19 20 21 22 |
# File 'lib/logstash/codecs/base.rb', line 17 def initialize(params={}) super config_init(@params) register if respond_to?(:register) setup_multi_encode! end |
Class Method Details
.plugin_type ⇒ Object
13 14 15 |
# File 'lib/logstash/codecs/base.rb', line 13 def self.plugin_type "codec" end |
Instance Method Details
#clone ⇒ Object
80 81 82 |
# File 'lib/logstash/codecs/base.rb', line 80 def clone return self.class.new(params) end |
#close ⇒ Object
64 |
# File 'lib/logstash/codecs/base.rb', line 64 def close; end |
#decode(data) ⇒ Object Also known as: <<
25 26 27 |
# File 'lib/logstash/codecs/base.rb', line 25 def decode(data) raise "#{self.class}#decode must be overidden" end |
#encode(event) ⇒ Object
DEPRECATED: Prefer defining encode_sync or multi_encode
33 34 35 36 |
# File 'lib/logstash/codecs/base.rb', line 33 def encode(event) encoded = multi_encode([event]) encoded.each {|event,data| @on_event.call(event,data) } end |
#flush(&block) ⇒ Object
73 74 75 76 77 |
# File 'lib/logstash/codecs/base.rb', line 73 def flush(&block) # does nothing by default. # if your codec needs a flush method (like you are spooling things) # you must implement this. end |
#multi_encode(events) ⇒ Object
Relies on the codec being synchronous (which they all are!) We need a better long term design here, but this is an improvement over the current API for shared plugins It is best if the codec implements this directly
43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/logstash/codecs/base.rb', line 43 def multi_encode(events) if @has_encode_sync events.map {|event| [event, self.encode_sync(event)]} else batch = Thread.current[:logstash_output_codec_batch] ||= [] batch.clear events.each {|event| self.encode(event) } batch end end |
#on_event(&block) ⇒ Object
68 69 70 |
# File 'lib/logstash/codecs/base.rb', line 68 def on_event(&block) @on_event = block end |
#setup_multi_encode! ⇒ Object
55 56 57 58 59 60 61 |
# File 'lib/logstash/codecs/base.rb', line 55 def setup_multi_encode! @has_encode_sync = self.methods.include?(:encode_sync) on_event do |event, data| Thread.current[:logstash_output_codec_batch] << [event, data] end end |