lib/fluent/plugin/out_map.rb in fluent-plugin-map-0.0.6 vs lib/fluent/plugin/out_map.rb in fluent-plugin-map-0.1.0
- old
+ new
@@ -1,15 +1,34 @@
+#
+# fluent-plugin-map
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
module Fluent
class MapOutput < Fluent::Output
Fluent::Plugin.register_output('map', self)
# Define `router` method of v0.12 to support v0.10 or earlier
unless method_defined?(:router)
define_method("router") { Fluent::Engine }
end
+ unless method_defined?(:log)
+ define_method("log") { $log }
+ end
+
config_param :map, :string, :default => nil
config_param :tag, :string, :default => nil
config_param :key, :string, :default => nil #deprecated
config_param :time, :string, :default => nil
config_param :record, :string, :default => nil
@@ -22,10 +41,15 @@
def configure(conf)
super
@format = determine_format()
configure_format()
@map = create_map(conf)
+ singleton_class.module_eval(<<-CODE)
+ def map_func(tag, time, record)
+ #{@map}
+ end
+ CODE
end
def determine_format()
if @format
@format
@@ -108,11 +132,11 @@
end
chain.next
tag_output_es
rescue SyntaxError => e
chain.next
- $log.error "map command is syntax error: #{@map}"
+ log.error "map command is syntax error: #{@map}"
e #for test
end
end
def do_map(tag, es)
@@ -122,19 +146,19 @@
tuples.each do |tag, time, record|
if time == nil || record == nil
raise SyntaxError.new
end
tag_output_es[tag].add(time, record)
- $log.trace { [tag, time, record].inspect }
+ log.trace { [tag, time, record].inspect }
end
tag_output_es
end
def generate_tuples(tag, es)
tuples = []
es.each {|time, record|
- new_tuple = eval(@map)
+ new_tuple = map_func(tag, time, record)
tuples.concat new_tuple
}
tuples
end
@@ -142,10 +166,10 @@
begin
Timeout.timeout(@timeout){
yield
}
rescue Timeout::Error
- $log.error {"Timeout: #{Time.at(time)} #{tag} #{record.inspect}"}
+ log.error {"Timeout: #{Time.at(time)} #{tag} #{record.inspect}"}
end
end
end
end