Class: LogStash::DateNode

Inherits:
Object
  • Object
show all
Defined in:
lib/logstash/string_interpolation.rb

Instance Method Summary collapse

Constructor Details

#initialize(format) ⇒ DateNode

Returns a new instance of DateNode.



124
125
126
127
128
# File 'lib/logstash/string_interpolation.rb', line 124

def initialize(format)
  @format = format
  @formatter = org.joda.time.format.DateTimeFormat.forPattern(@format)
      .withZone(org.joda.time.DateTimeZone::UTC)
end

Instance Method Details

#evaluate(event) ⇒ Object

Raises:



130
131
132
133
134
135
136
137
138
# File 'lib/logstash/string_interpolation.rb', line 130

def evaluate(event)
  t = event.timestamp

  raise LogStash::Error, "Unable to format in string \"#{@format}\", #{LogStash::Event::TIMESTAMP} field not found" unless t

  org.joda.time.Instant.java_class.constructor(Java::long).new_instance(
    t.tv_sec * 1000 + t.tv_usec / 1000
  ).to_java.toDateTime.toString(@formatter)
end