Class: FluentExt::TextParser::GenericParser

Inherits:
Object
  • Object
show all
Includes:
Fluent::Configurable
Defined in:
lib/fluent/plugin/fixed_parser.rb

Instance Method Summary collapse

Instance Method Details

#parse_time(record) ⇒ Object



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/fluent/plugin/fixed_parser.rb', line 19

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