Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

directly use buftok to avoid indirection through the line codec #18

Merged
merged 3 commits into from
Feb 5, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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

Expand Down
22 changes: 11 additions & 11 deletions lib/logstash/codecs/json_lines.rb
Original file line number Diff line number Diff line change
@@ -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.
Expand All @@ -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`
#
Expand All @@ -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

Expand All @@ -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

Expand Down
4 changes: 2 additions & 2 deletions logstash-codec-json_lines.gemspec
Original file line number Diff line number Diff line change
@@ -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"
Expand All @@ -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)/})
Expand Down
2 changes: 2 additions & 0 deletions spec/codecs/json_lines_spec.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# encoding: utf-8

require "logstash/codecs/json_lines"
require "logstash/event"
require "logstash/json"
Expand Down