Class: LogStash::Filters::JSONEncode
- Defined in:
- lib/logstash/filters/json_encode.rb
Overview
JSON encode filter. Takes a field and serializes it into JSON
If no target is specified, the source field is overwritten with the JSON text.
For example, if you have a field named ‘foo’, and you want to store the JSON encoded string in ‘bar’, do this:
filter {
json_encode {
source => "foo"
target => "bar"
}
}
Constant Summary
Constants inherited from Base
Constants included from Config::Mixin
Instance Attribute Summary
Attributes included from Config::Mixin
Attributes inherited from Plugin
Instance Method Summary collapse
Methods inherited from Base
#execute, #initialize, #threadsafe?
Methods included from 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::Filters::Base
Instance Method Details
#filter(event) ⇒ Object
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/logstash/filters/json_encode.rb', line 37 def filter(event) return unless filter?(event) @logger.debug("Running JSON encoder", :event => event) begin event[@target] = JSON.pretty_generate(event[@source]) filter_matched(event) rescue => e event.tag "_jsongeneratefailure" @logger.warn("Trouble encoding JSON", :source => @source, :raw => event[@source].inspect, :exception => e) end @logger.debug? && @logger.debug("Event after JSON encoder", :event => event) end |
#register ⇒ Object
32 33 34 |
# File 'lib/logstash/filters/json_encode.rb', line 32 def register @target = @source if @target.nil? end |