mirror of
https://github.com/elastic/logstash.git
synced 2025-04-24 06:37:19 -04:00
support message_format to build a @message when the the input is raw json
This commit is contained in:
parent
569af86ce1
commit
21eb144b8c
1 changed files with 11 additions and 2 deletions
|
@ -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)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue