mirror of
https://github.com/elastic/logstash.git
synced 2025-04-24 14:47:19 -04:00
codec support for outputs. converted stdout output to use codecs.
This commit is contained in:
parent
2c52fbac56
commit
a30303949c
3 changed files with 28 additions and 29 deletions
|
@ -48,6 +48,9 @@ class LogStash::Outputs::Base < LogStash::Plugin
|
|||
# Don't send events that have @timestamp older than specified number of seconds.
|
||||
config :ignore_older_than, :validate => :number, :default => 0
|
||||
|
||||
# The codec used for output data
|
||||
config :codec, :validate => :string, :default => 'plain'
|
||||
|
||||
public
|
||||
def initialize(params)
|
||||
super
|
||||
|
@ -72,6 +75,11 @@ class LogStash::Outputs::Base < LogStash::Plugin
|
|||
raise "#{self.class}#receive must be overidden"
|
||||
end # def receive
|
||||
|
||||
protected
|
||||
def enable_codecs
|
||||
@codec = LogStash::Codecs.for(@codec).new
|
||||
end
|
||||
|
||||
public
|
||||
def handle(event)
|
||||
if event == LogStash::SHUTDOWN
|
||||
|
|
|
@ -14,56 +14,46 @@ class LogStash::Outputs::Stdout < LogStash::Outputs::Base
|
|||
config :debug, :validate => :boolean
|
||||
|
||||
# Debug output format: ruby (default), json
|
||||
config :debug_format, :default => "ruby", :validate => ["ruby", "json", "dots"]
|
||||
config :debug_format, :default => "ruby", :validate => ["ruby", "dots"]
|
||||
|
||||
# The message to emit to stdout.
|
||||
config :message, :validate => :string, :default => "%{+yyyy-MM-dd'T'HH:mm:ss.SSSZ} %{host}: %{message}"
|
||||
|
||||
public
|
||||
def register
|
||||
enable_codecs
|
||||
begin
|
||||
@codec.format = @message
|
||||
rescue NoMethodError
|
||||
end
|
||||
@print_method = method(:ap) rescue method(:p)
|
||||
if @debug
|
||||
case @debug_format
|
||||
when "ruby"
|
||||
define_singleton_method(:receive) do |event|
|
||||
return unless output?(event)
|
||||
if event == LogStash::SHUTDOWN
|
||||
finished
|
||||
return
|
||||
end
|
||||
@codec.on_event do |event|
|
||||
@print_method.call(event)
|
||||
end
|
||||
when "json"
|
||||
define_singleton_method(:receive) do |event|
|
||||
return unless output?(event)
|
||||
if event == LogStash::SHUTDOWN
|
||||
finished
|
||||
return
|
||||
end
|
||||
puts event.to_json
|
||||
end
|
||||
when "dots"
|
||||
define_singleton_method(:receive) do |event|
|
||||
return unless output?(event)
|
||||
if event == LogStash::SHUTDOWN
|
||||
finished
|
||||
return
|
||||
end
|
||||
@codec.on_event do |event|
|
||||
$stdout.write(".")
|
||||
end
|
||||
else
|
||||
raise "unknown debug_format #{@debug_format}, this should never happen"
|
||||
end
|
||||
else
|
||||
define_singleton_method(:receive) do |event|
|
||||
return unless output?(event)
|
||||
if event == LogStash::SHUTDOWN
|
||||
finished
|
||||
return
|
||||
end
|
||||
puts event.sprintf(@message)
|
||||
@codec.on_event do |event|
|
||||
puts event
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def receive(event)
|
||||
return unless output?(event)
|
||||
if event == LogStash::SHUTDOWN
|
||||
finished
|
||||
return
|
||||
end
|
||||
@codec.encode(event)
|
||||
end
|
||||
|
||||
end # class LogStash::Outputs::Stdout
|
||||
|
|
|
@ -40,6 +40,7 @@ Gem::Specification.new do |gem|
|
|||
gem.add_runtime_dependency "heroku" #(MIT license)
|
||||
gem.add_runtime_dependency "addressable" #(Apache 2.0 license)
|
||||
gem.add_runtime_dependency "bunny", ["0.8.0"] #(MIT license)
|
||||
gem.add_runtime_dependency "extlib", ["0.9.16"] #(MIT license)
|
||||
gem.add_runtime_dependency "ffi" #(LGPL-3 license)
|
||||
gem.add_runtime_dependency "ffi-rzmq", ["1.0.0"] #(MIT license)
|
||||
gem.add_runtime_dependency "filewatch", ["0.5.1"] #(BSD license)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue