diff --git a/CHANGELOG.md b/CHANGELOG.md index 21f7720..c1405e5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,6 @@ +## 2.0.5 + - Directly use buftok to avoid indirection through the line codec https://github.com/logstash-plugins/logstash-codec-json_lines/pull/18 + ## 2.0.4 - Support for customizable delimiter diff --git a/lib/logstash/codecs/json_lines.rb b/lib/logstash/codecs/json_lines.rb index 3ee2d90..7fb865c 100644 --- a/lib/logstash/codecs/json_lines.rb +++ b/lib/logstash/codecs/json_lines.rb @@ -1,6 +1,7 @@ # encoding: utf-8 require "logstash/codecs/base" -require "logstash/codecs/line" +require "logstash/util/charset" +require "logstash/util/buftok" require "logstash/json" # This codec will decode streamed JSON that is newline delimited. @@ -13,7 +14,6 @@ class LogStash::Codecs::JSONLines < LogStash::Codecs::Base config_name "json_lines" - # The character encoding used in this codec. Examples include `UTF-8` and # `CP1252` # @@ -30,15 +30,15 @@ class LogStash::Codecs::JSONLines < LogStash::Codecs::Base public - def initialize(params={}) - super(params) - @lines = LogStash::Codecs::Line.new("delimiter" => @delimiter) - @lines.charset = @charset + def register + @buffer = FileWatch::BufferedTokenizer.new(@delimiter) + @converter = LogStash::Util::Charset.new(@charset) + @converter.logger = @logger end def decode(data) - @lines.decode(data) do |event| - yield guard(event, data) + @buffer.extract(data).each do |line| + yield guard(@converter.convert(line)) end end # def decode @@ -50,11 +50,11 @@ def encode(event) private - def guard(event, data) + def guard(data) begin - LogStash::Event.new(LogStash::Json.load(event["message"])) + LogStash::Event.new(LogStash::Json.load(data)) rescue LogStash::Json::ParserError => e - LogStash::Event.new("message" => event["message"], "tags" => ["_jsonparsefailure"]) + LogStash::Event.new("message" => data, "tags" => ["_jsonparsefailure"]) end end diff --git a/logstash-codec-json_lines.gemspec b/logstash-codec-json_lines.gemspec index cd113af..d83281f 100644 --- a/logstash-codec-json_lines.gemspec +++ b/logstash-codec-json_lines.gemspec @@ -1,7 +1,7 @@ Gem::Specification.new do |s| s.name = 'logstash-codec-json_lines' - s.version = '2.0.4' + s.version = '2.0.5' s.licenses = ['Apache License (2.0)'] s.summary = "This codec will decode streamed JSON that is newline delimited." s.description = "This gem is a logstash plugin required to be installed on top of the Logstash core pipeline using $LS_HOME/bin/plugin install gemname. This gem is not a stand-alone program" @@ -11,7 +11,7 @@ Gem::Specification.new do |s| s.require_paths = ["lib"] # Files - s.files = Dir['lib/**/*','spec/**/*','vendor/**/*','*.gemspec','*.md','CONTRIBUTORS','Gemfile','LICENSE','NOTICE.TXT'] + s.files = Dir['lib/**/*','spec/**/*','*.gemspec','*.md','CONTRIBUTORS','Gemfile','LICENSE','NOTICE.TXT'] # Tests s.test_files = s.files.grep(%r{^(test|spec|features)/}) diff --git a/spec/codecs/json_lines_spec.rb b/spec/codecs/json_lines_spec.rb index 4b0ccec..af933f5 100644 --- a/spec/codecs/json_lines_spec.rb +++ b/spec/codecs/json_lines_spec.rb @@ -1,3 +1,5 @@ +# encoding: utf-8 + require "logstash/codecs/json_lines" require "logstash/event" require "logstash/json"