lib/fluent/plugin/out_yohoushi.rb in fluent-plugin-yohoushi-0.1.2 vs lib/fluent/plugin/out_yohoushi.rb in fluent-plugin-yohoushi-0.1.3

- old
+ new

@@ -1,9 +1,14 @@ module Fluent class YohoushiOutput < Output Plugin.register_output('yohoushi', self) + # To support log_level option implemented by Fluentd v0.10.43 + unless method_defined?(:log) + define_method("log") { $log } + end + MAPPING_MAX_NUM = 20 KEY_MAX_NUM = 20 def initialize super @@ -51,15 +56,10 @@ from, to = conf["mapping#{i}"].split(/ +/, 2) raise ConfigError, "mapping#{i} does not contain 2 parameters" unless to @mapping[from] = to end @client = MultiForecast::Client.new('mapping' => @mapping) unless @mapping.empty? - @client.clients.each { |c| - c.connect_timeout = 5.0 - c.send_timeout = 5.0 - c.receive_timeout = 5.0 - } end raise ConfigError, "Either of `base_uri` or `mapping1` must be specified" unless @client if @key_pattern key_pattern, @key_pattern_path = @key_pattern.split(/ +/, 2) @@ -105,11 +105,11 @@ @client.post_graph(path, { 'number' => number.to_f, 'mode' => @mode.to_s }) else @client.post_graph(path, { 'number' => number.to_i, 'mode' => @mode.to_s }) end rescue => e - $log.warn "out_yohoushi: #{e.class} #{e.message} #{path} #{e.backtrace.first}" + log.warn "out_yohoushi: #{e.class} #{e.message} #{path} #{e.backtrace.first}" end def emit(tag, es, chain) tag_parts = tag.split('.') tag_prefix = tag_prefix(tag_parts) @@ -142,11 +142,11 @@ end end chain.next rescue => e - $log.warn "out_yohoushi: #{e.class} #{e.message} #{e.backtrace.first}" + log.warn "out_yohoushi: #{e.class} #{e.message} #{e.backtrace.first}" end def expand_placeholder(value, time, record, opts) @placeholder_expander.prepare_placeholders(time, record, opts) @placeholder_expander.expand(value) @@ -193,10 +193,10 @@ @placeholders = placeholders end def expand(str) str.gsub(/(\${[a-z_]+(\[-?[0-9]+\])?}|__[A-Z_]+__)/) { - $log.warn "record_reformer: unknown placeholder `#{$1}` found" unless @placeholders.include?($1) + log.warn "record_reformer: unknown placeholder `#{$1}` found" unless @placeholders.include?($1) @placeholders[$1] } end end