Class: FluentExt::TextParser::RegexpParser

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

Instance Method Summary collapse

Constructor Details

#initialize(regexp, conf = {}) ⇒ RegexpParser

Returns a new instance of RegexpParser.



13
14
15
16
17
18
19
# File 'lib/fluent/plugin/fixed_parser.rb', line 13

def initialize(regexp, conf={})
  super()
  @regexp = regexp
  unless conf.empty?
    configure(conf)
  end
end

Instance Method Details

#call(text) ⇒ Object



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 21

def call(text)
  m = @regexp.match(text)
  unless m
    unless @suppress_parse_error_log
      $log.warn "pattern not match: #{text}"
    end

    return nil, nil
  end

  time = nil
  record = {}

  m.names.each {|name|
    if value = m[name]
      case name
      when "time"
        if @time_format
          time = Time.strptime(value, @time_format).to_i
        else
          time = Time.parse(value).to_i
        end
      else
        record[name] = value
      end
    end
  }

  return time, record
end