mirror of
https://github.com/elastic/logstash.git
synced 2025-04-24 06:37:19 -04:00
support debug_format: ruby or json debug output. also fix HAVE_AWESOME_PRINT hack; if require ap already failed in logging.rb, it just returns false here
This commit is contained in:
parent
e0f23b0f9c
commit
4627a8e6d7
1 changed files with 18 additions and 9 deletions
|
@ -3,10 +3,8 @@ require "logstash/namespace"
|
|||
|
||||
class LogStash::Outputs::Stdout < LogStash::Outputs::Base
|
||||
begin
|
||||
require "ap"
|
||||
HAVE_AWESOME_PRINT = true
|
||||
require "ap"
|
||||
rescue LoadError
|
||||
HAVE_AWESOME_PRINT = false
|
||||
end
|
||||
|
||||
config_name "stdout"
|
||||
|
@ -14,16 +12,24 @@ class LogStash::Outputs::Stdout < LogStash::Outputs::Base
|
|||
# Enable debugging. Tries to pretty-print the entire event object.
|
||||
config :debug, :validate => :boolean
|
||||
|
||||
# Debug output format: ruby (default), json
|
||||
config :debug_format, :default => ["ruby"], :validate => (lambda do |value|
|
||||
valid_formats = ["ruby", "json"]
|
||||
if value.length != 1
|
||||
false
|
||||
else
|
||||
valid_formats.member?(value.first)
|
||||
end
|
||||
end) # config :debug_format
|
||||
|
||||
public
|
||||
def initialize(params)
|
||||
super
|
||||
|
||||
#@debug ||= false
|
||||
end
|
||||
|
||||
public
|
||||
def register
|
||||
# nothing to do
|
||||
@print_method = method(:ap) rescue method(:p)
|
||||
end
|
||||
|
||||
public
|
||||
|
@ -34,10 +40,13 @@ class LogStash::Outputs::Stdout < LogStash::Outputs::Base
|
|||
end
|
||||
|
||||
if @debug
|
||||
if HAVE_AWESOME_PRINT
|
||||
ap event.to_hash
|
||||
case @debug_format.first
|
||||
when "ruby":
|
||||
@print_method.call(event.to_hash)
|
||||
when "json":
|
||||
puts event.to_json
|
||||
else
|
||||
p event.to_hash
|
||||
raise "unknown debug_format #{@debug_format}, this should never happen"
|
||||
end
|
||||
else
|
||||
puts event.to_s
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue