support message_format to build a @message when the the input is raw json

This commit is contained in:
Pete Fritchman 2011-05-20 23:30:57 -07:00
parent 569af86ce1
commit 21eb144b8c

View file

@ -26,6 +26,11 @@ class LogStash::Inputs::Base < LogStash::Plugin
end
end) # config :format
# If format is "json", an event sprintf string to build what
# the display @message should be (defaults to the raw JSON).
# sprintf format strings look like %{fieldname} or %{@metadata}.
config :message_format, :validate => :string
# Add any number of arbitrary tags to your event.
#
# This can help with processing later.
@ -72,8 +77,6 @@ class LogStash::Inputs::Base < LogStash::Plugin
when "plain":
event.message = raw
when "json":
# TODO(petef): format string to generate @message
event.message = "RAW JSON: #{raw}"
begin
fields = JSON.parse(raw)
fields.each { |k, v| event[k] = v }
@ -84,6 +87,12 @@ class LogStash::Inputs::Base < LogStash::Plugin
})
return nil
end
if @message_format
event.message = event.sprintf(@message_format)
else
event.message = raw
end
when "json_event":
begin
event = LogStash::Event.from_json(raw)