class FluentExt::GenericParser

Attributes

log[RW]

Public Class Methods

new(logger) click to toggle source
Calls superclass method
# File lib/fluent/plugin/parser.rb, line 15
def initialize(logger)
  super()

  @cache1_key = nil
  @cache1_time = nil
  @cache2_key = nil
  @cache2_time = nil

  @log = logger
end

Public Instance Methods

parse_time(record) click to toggle source
# File lib/fluent/plugin/parser.rb, line 26
def parse_time(record)
  time = nil

  unless @time_parse
    return time, record
  end

  if value = record.delete(@time_key)
    if @cache1_key == value
      time = @cache1_time
    elsif @cache2_key == value
      time = @cache2_time
    else
      begin
        time = if @time_format
                 Time.strptime(value, @time_format).to_i
               else
                 Time.parse(value).to_i
               end
        @cache1_key = @cache2_key
        @cache1_time = @cache2_time
        @cache2_key = value
        @cache2_time = time
      rescue TypeError, ArgumentError => e
        @log.warn "Failed to parse time", :key => @time_key, :value => value
        record[@time_key] = value
      end
    end
  end

  return time, record
end