Merge pull request #625 from jdve/date-overwrite

filters: date: add target option
This commit is contained in:
Nick Ethier 2013-09-23 11:25:57 -07:00
commit bb6a4f9a7e

View file

@ -79,6 +79,10 @@ class LogStash::Filters::Date < LogStash::Filters::Base
# #
config :match, :validate => :array, :default => [] config :match, :validate => :array, :default => []
# Store the matching timestamp into the given target field. If not provided,
# default to updating the @timestamp field of the event.
config :target, :validate => :string, :default => "@timestamp"
# LOGSTASH-34 # LOGSTASH-34
DATEPATTERNS = %w{ y d H m s S } DATEPATTERNS = %w{ y d H m s S }
@ -208,12 +212,13 @@ class LogStash::Filters::Date < LogStash::Filters::Base
time = time.withZone(UTC) time = time.withZone(UTC)
# Convert joda DateTime to a ruby Time # Convert joda DateTime to a ruby Time
event["@timestamp"] = Time.utc( event[@target] = Time.utc(
time.getYear, time.getMonthOfYear, time.getDayOfMonth, time.getYear, time.getMonthOfYear, time.getDayOfMonth,
time.getHourOfDay, time.getMinuteOfHour, time.getSecondOfMinute, time.getHourOfDay, time.getMinuteOfHour, time.getSecondOfMinute,
time.getMillisOfSecond * 1000 time.getMillisOfSecond * 1000
) )
@logger.debug? && @logger.debug("Date parsing done", :value => value, :timestamp => event["@timestamp"])
@logger.debug? && @logger.debug("Date parsing done", :value => value, :timestamp => event[@target])
rescue StandardError, JavaException => e rescue StandardError, JavaException => e
@logger.warn("Failed parsing date from field", :field => field, @logger.warn("Failed parsing date from field", :field => field,
:value => value, :exception => e) :value => value, :exception => e)