@@ -44,6 +44,9 @@ def initialize
4444 config_param :in_keys , :default => [ ] do |val |
4545 val . split ( ',' )
4646 end
47+ config_param :in_tag_key , :default => nil
48+ config_param :in_time_key , :default => nil
49+ config_param :in_time_format , :default => nil
4750
4851 config_param :out_format , :default => :tsv do |val |
4952 f = SUPPORTED_FORMAT [ val ]
@@ -53,9 +56,11 @@ def initialize
5356 config_param :out_keys , :default => [ ] do |val | # for tsv format
5457 val . split ( ',' )
5558 end
59+ config_param :out_tag_key , :default => nil
60+ config_param :out_time_key , :default => nil
61+ config_param :out_time_format , :default => nil
5662
5763 config_param :tag , :string , :default => nil
58- config_param :tag_key , :string , :default => nil
5964
6065 config_param :time_key , :string , :default => nil
6166 config_param :time_format , :string , :default => nil
@@ -66,6 +71,24 @@ def initialize
6671 config_set_default :flush_interval , 1
6772
6873 def configure ( conf )
74+ if tag_key = conf [ 'tag_key' ]
75+ # TODO obsoleted?
76+ @in_tag_key = tag_key
77+ @out_tag_key = tag_key
78+ end
79+
80+ if time_key = conf [ 'time_key' ]
81+ # TODO obsoleted?
82+ @in_time_key = time_key
83+ @out_time_key = time_key
84+ end
85+
86+ if time_format = conf [ 'time_format' ]
87+ # TODO obsoleted?
88+ @in_time_format = time_format
89+ @out_time_format = time_format
90+ end
91+
6992 super
7093
7194 if localtime = conf [ 'localtime' ]
@@ -74,20 +97,29 @@ def configure(conf)
7497 @localtime = false
7598 end
7699
77- if !@tag && !@tag_key
78- raise ConfigError , "'tag' or 'tag_key ' option is required on exec_filter output"
100+ if !@tag && !@out_tag_key
101+ raise ConfigError , "'tag' or 'out_tag_key ' option is required on exec_filter output"
79102 end
80103
81- if @time_key
82- if @time_format
83- f = @time_format
104+ if @in_time_key
105+ if f = @in_time_format
84106 tf = TimeFormatter . new ( f , @localtime )
85107 @time_format_proc = tf . method ( :format )
86- @time_parse_proc = Proc . new { |str | Time . strptime ( str , f ) . to_i }
87108 else
88109 @time_format_proc = Proc . new { |time | time . to_s }
110+ end
111+ elsif @in_time_format
112+ $log. warn "in_time_format effects nothing when in_time_key is not specified: #{ conf } "
113+ end
114+
115+ if @out_time_key
116+ if f = @out_time_format
117+ @time_parse_proc = Proc . new { |str | Time . strptime ( str , f ) . to_i }
118+ else
89119 @time_parse_proc = Proc . new { |str | str . to_i }
90120 end
121+ elsif @out_time_format
122+ $log. warn "out_time_format effects nothing when out_time_key is not specified: #{ conf } "
91123 end
92124
93125 if @remove_prefix
@@ -164,11 +196,11 @@ def format_stream(tag, es)
164196 out = ''
165197
166198 es . each { |time , record |
167- if @time_key
168- record [ @time_key ] = @time_format_proc . call ( time )
199+ if @in_time_key
200+ record [ @in_time_key ] = @time_format_proc . call ( time )
169201 end
170- if @tag_key
171- record [ @tag_key ] = tag
202+ if @in_tag_key
203+ record [ @in_tag_key ] = tag
172204 end
173205 @formatter . call ( record , out )
174206 }
@@ -267,13 +299,13 @@ def call(record, out)
267299 end
268300
269301 def on_message ( record )
270- if val = record . delete ( @time_key )
302+ if val = record . delete ( @out_time_key )
271303 time = @time_parse_proc . call ( val )
272304 else
273305 time = Engine . now
274306 end
275307
276- if val = record . delete ( @tag_key )
308+ if val = record . delete ( @out_tag_key )
277309 tag = if @add_prefix
278310 @added_prefix_string + val
279311 else
0 commit comments