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.



142
143
144
145
146
# File 'lib/logstash/string_interpolation.rb', line 142

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:

  • (LogStash::Error)


148
149
150
151
152
153
154
155
156
# File 'lib/logstash/string_interpolation.rb', line 148

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