- start working on date support for Event#sprintf

This commit is contained in:
Jordan Sissel 2011-03-18 22:41:47 -07:00
parent c9edd1380a
commit f7c76431c9

View file

@ -134,14 +134,22 @@ class LogStash::Event
public public
def sprintf(format) def sprintf(format)
return format.gsub(/%\{[^}]+\}/) do |tok| return format.gsub(/%\{[^}]+\}/) do |tok|
# Take the inside of the %{ ... }
key = tok[2 ... -1] key = tok[2 ... -1]
value = self[key]
if value.nil? if key[0,1] == "+"
tok # leave the %{foo} if this field does not exist in this event. # Use a time format.
elsif value.is_a?(Array) # TODO(sissel): http://code.google.com/p/logstash/issues/detail?id=38
value.join(",") # Join by ',' if value is an rray else
else # Use an event field.
value # otherwise return the value value = self[key]
if value.nil?
tok # leave the %{foo} if this field does not exist in this event.
elsif value.is_a?(Array)
value.join(",") # Join by ',' if value is an rray
else
value # otherwise return the value
end
end end
end end
end # def sprintf end # def sprintf