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.



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

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:



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

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