-
Notifications
You must be signed in to change notification settings - Fork 15
/
Copy pathparser_multi_format.rb
49 lines (42 loc) · 1.2 KB
/
parser_multi_format.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
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
require 'fluent/plugin/parser'
module Fluent
module Plugin
class MultiFormatParser < Parser
Plugin.register_parser('multi_format', self)
config_param :format_key, :string, default: nil
def initialize
super
@parsers = []
@parser_format_names = []
end
def configure(conf)
super
conf.elements.each_with_index { |e, i|
next unless ['pattern', 'format'].include?(e.name)
next if e['format'].nil? && (e['@type'] == 'multi_format')
@parser_format_names << e.delete('format_name') || ""+e['format']+"#"+i.to_s
parser = Plugin.new_parser(e['format'])
parser.configure(e)
@parsers << parser
}
end
def parse(text)
@parsers.each_with_index { |parser, i|
begin
parser.parse(text) { |time, record|
if time && record
if @format_key
record[@format_key] = @parser_format_names[i]
end
yield time, record
return
end
}
rescue # ignore parser error
end
}
yield nil, nil
end
end
end
end