forked from elastic/logstash
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
20 changed files
with
374 additions
and
80 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
.*.swp | ||
*.gem | ||
*.class | ||
.rbx | ||
Gemfile.lock | ||
.rbx | ||
*.tar.gz | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
require "logstash/namespace" | ||
require "logstash/event" | ||
require "logstash/plugin" | ||
require "logstash/logging" | ||
require "extlib" | ||
|
||
# This is the base class for logstash codecs. | ||
module LogStash::Codecs | ||
public | ||
def self.for(codec) | ||
return codec unless codec.is_a? String | ||
|
||
#TODO: codec paths or just use plugin paths | ||
plugin = File.join('logstash', 'codecs', codec) + ".rb" | ||
#@logger.info "Loading codec", :codec => plugin | ||
require plugin | ||
klass_name = codec.camel_case | ||
if LogStash::Codecs.const_defined?(klass_name) | ||
return LogStash::Codecs.const_get(klass_name) | ||
end | ||
nil | ||
end | ||
|
||
class Base < LogStash::Plugin | ||
|
||
attr_reader :on_event | ||
attr_accessor :charset | ||
|
||
public | ||
def decode(data) | ||
raise "#{self.class}#decode must be overidden" | ||
end # def decode | ||
|
||
alias_method :<<, :decode | ||
|
||
public | ||
def encode(data) | ||
raise "#{self.class}#encode must be overidden" | ||
end # def encode | ||
|
||
public | ||
def on_event(&block) | ||
@on_event = block | ||
end | ||
|
||
end # class LogStash::Codecs::Base | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
require "logstash/codecs/base" | ||
require "json" | ||
|
||
# This is the base class for logstash codecs. | ||
class LogStash::Codecs::Json < LogStash::Codecs::Base | ||
public | ||
def decode(data) | ||
yield LogStash::Event.new(JSON.parse(data.force_encoding("UTF-8"))) | ||
end # def decode | ||
|
||
public | ||
def encode(data) | ||
@on_event.call data.to_json | ||
end # def encode | ||
|
||
end # class LogStash::Codecs::Json |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
require "logstash/codecs/base" | ||
require "logstash/codecs/spool" | ||
|
||
# This is the base class for logstash codecs. | ||
class LogStash::Codecs::JsonSpooler < LogStash::Codecs::Base | ||
public | ||
def initialize | ||
@spooler = LogStash::Codecs::Spool.new | ||
@spooler.on_event do |data| | ||
@on_event.call data.to_json | ||
end | ||
end | ||
public | ||
def decode(data) | ||
@spooler.decode(JSON.parse(data.force_encoding("UTF-8"))) do |event| | ||
yield event | ||
end | ||
end # def decode | ||
|
||
public | ||
def encode(data) | ||
@spooler.encode(data) | ||
end # def encode | ||
|
||
end # class LogStash::Codecs::Json |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
require "logstash/codecs/base" | ||
|
||
class LogStash::Codecs::Noop < LogStash::Codecs::Base | ||
public | ||
def decode(data) | ||
yield data | ||
end # def decode | ||
|
||
public | ||
def encode(data) | ||
@on_event.call data | ||
end # def encode | ||
|
||
end # class LogStash::Codecs::Noop |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
require "logstash/codecs/base" | ||
|
||
# This is the base class for logstash codecs. | ||
class LogStash::Codecs::Plain < LogStash::Codecs::Base | ||
attr_accessor :format | ||
|
||
public | ||
def decode(data) | ||
data.force_encoding(@charset) | ||
if @charset != "UTF-8" | ||
# Convert to UTF-8 if not in that character set. | ||
data = data.encode("UTF-8", :invalid => :replace, :undef => :replace) | ||
end | ||
yield LogStash::Event.new({"message" => data}) | ||
end # def decode | ||
|
||
public | ||
def encode(data) | ||
if data.is_a? LogStash::Event and !@format.nil? | ||
@on_event.call data.sprintf(@format) | ||
else | ||
@on_event.call data.to_s | ||
end | ||
end # def encode | ||
|
||
end # class LogStash::Codecs::Plain |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
require "logstash/codecs/base" | ||
|
||
class LogStash::Codecs::Spool < LogStash::Codecs::Base | ||
|
||
attr_reader :buffer | ||
|
||
public | ||
def decode(data) | ||
data.each do |event| | ||
yield event | ||
end | ||
end # def decode | ||
|
||
public | ||
def encode(data) | ||
@buffer = [] if @buffer.nil? | ||
#buffer size is hard coded for now until a | ||
#better way to pass args into codecs is implemented | ||
if @buffer.length >= 50 | ||
@on_event.call @buffer | ||
@buffer = [] | ||
else | ||
@buffer << data | ||
end | ||
end # def encode | ||
|
||
end # class LogStash::Codecs::Spool |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.