@@ -36,6 +36,9 @@ def initialize(plugin, conf)
3636 if @plugin . respond_to? ( :keep_time_key )
3737 @keep_time_key = @plugin . keep_time_key
3838 end
39+ if @plugin . respond_to? ( :time_format )
40+ @time_format = @plugin . time_format
41+ end
3942 end
4043
4144 def add_patterns_from_file ( path )
@@ -48,10 +51,10 @@ def add_patterns_from_file(path)
4851
4952 def setup
5053 if @plugin . grok_pattern
51- @parsers [ :grok_pattern ] = expand_pattern_expression ( @plugin . grok_pattern , @conf )
54+ @parsers [ :grok_pattern ] = expand_pattern_expression_grok_pattern ( @plugin . grok_pattern , @conf )
5255 else
5356 @plugin . grok_confs . each . with_index do |grok_conf , index |
54- @parsers [ grok_conf . name || index ] = expand_pattern_expression ( grok_conf . pattern , grok_conf )
57+ @parsers [ grok_conf . name || index ] = expand_pattern_expression_grok_section ( grok_conf )
5558 end
5659 end
5760 @parsers . reject! do |key , parser |
@@ -64,7 +67,7 @@ def setup
6467
6568 private
6669
67- def expand_pattern_expression ( grok_pattern , conf )
70+ def expand_pattern_expression_grok_pattern ( grok_pattern , conf )
6871 regexp , types = expand_pattern ( grok_pattern )
6972 $log. info "Expanded the pattern #{ grok_pattern } into #{ regexp } "
7073 _conf = conf . to_h
@@ -83,6 +86,37 @@ def expand_pattern_expression(grok_pattern, conf)
8386 nil
8487 end
8588
89+ def expand_pattern_expression_grok_section ( conf )
90+ regexp , types = expand_pattern ( conf . pattern )
91+ $log. info "Expanded the pattern #{ conf . pattern } into #{ regexp } "
92+ _conf = conf . to_h
93+ unless types . empty?
94+ _conf [ "types" ] = types . map { |subname , type | "#{ subname } :#{ type } " } . join ( "," )
95+ end
96+ if conf [ "multiline" ] || @multiline_mode
97+ _conf [ "multiline" ] = conf [ "multiline" ] || @multiline_mode
98+ end
99+ if conf [ "keep_time_key" ] || @keep_time_key
100+ _conf [ "keep_time_key" ] = conf [ "keep_time_key" ] || @keep_time_key
101+ end
102+ if conf [ "time_key" ]
103+ _conf [ "time_key" ] = conf [ "time_key" ]
104+ end
105+ if conf [ "time_format" ] || @time_format
106+ _conf [ "time_format" ] = conf [ "time_format" ] || @time_format
107+ end
108+ _conf [ "expression" ] = regexp
109+ config = Fluent ::Config ::Element . new ( "parse" , "" , _conf , [ ] )
110+ parser = Fluent ::Plugin ::RegexpParser . new
111+ parser . configure ( config )
112+ parser
113+ rescue GrokPatternNotFoundError => e
114+ raise e
115+ rescue => e
116+ $log. error ( error : e )
117+ nil
118+ end
119+
86120 def expand_pattern ( pattern )
87121 # It's okay to modify in place. no need to expand it more than once.
88122 type_map = { }
0 commit comments