lib/fluent/plugin/out_forest.rb in fluent-plugin-forest-0.2.3 vs lib/fluent/plugin/out_forest.rb in fluent-plugin-forest-0.2.4

- old
+ new

@@ -7,10 +7,15 @@ config_param :hostname, :string, :default => `hostname`.chomp config_param :escape_tag_separator, :string, :default => '_' attr_reader :outputs + # Define `log` method for v0.10.42 or earlier + unless method_defined?(:log) + define_method("log") { $log } + end + def configure(conf) super if @remove_prefix @removed_prefix_string = @remove_prefix + '.' @@ -65,27 +70,27 @@ escaped_tag = tag.gsub('.', @escape_tag_separator) pairs = {} e.each do |k,v| v = v.gsub(/__TAG_PARTS\[-?[0-9]+(?:\.\.\.?-?[0-9]+)?\]__|\$\{tag_parts\[-?[0-9]+(?:\.\.\.?-?[0-9]+)?\]\}/) do |tag_parts_matched| matched = /\[(?<first>-?[0-9]+)(?<range_part>(?<range_type>\.\.\.?)(?<last>-?[0-9]+))?\]/.match(tag_parts_matched) - if matched && matched[:range_part] + raise "BUG: gsub regex matches but index regex does not match" unless matched + + if matched[:range_part] exclude_end = (matched[:range_type] == '...') range = Range.new(matched[:first].to_i, matched[:last].to_i, exclude_end) if tag_parts[range] tag_parts[range].join(".") else - $log.warn "out_forest: missing placeholder. tag:#{tag} placeholder:#{tag_parts_matched} conf:#{k} #{v}" + log.warn "out_forest: missing placeholder. tag:#{tag} placeholder:#{tag_parts_matched} conf:#{k} #{v}" nil end - elsif matched # non range index (without range_part) + else # non range index (without range_part) index = matched[:first].to_i unless tag_parts[index] - $log.warn "out_forest: missing placeholder. tag:#{tag} placeholder:#{tag_parts_matched} conf:#{k} #{v}" + log.warn "out_forest: missing placeholder. tag:#{tag} placeholder:#{tag_parts_matched} conf:#{k} #{v}" end tag_parts[index] - else - raise "BUG: gsub regex matches but index regex does not match" end end v = v.gsub('__ESCAPED_TAG__', escaped_tag).gsub('${escaped_tag}', escaped_tag) pairs[k] = v.gsub('__TAG__', tag).gsub('${tag}', tag).gsub('__HOSTNAME__', @hostname).gsub('${hostname}', @hostname) end @@ -128,19 +133,19 @@ output.start @mapping[tag] = output @outputs.push(output) end } - $log.info "out_forest plants new output: #{@subtype} for tag '#{tag}'" + log.info "out_forest plants new output: #{@subtype} for tag '#{tag}'" rescue Fluent::ConfigError => e - $log.error "failed to configure sub output #{@subtype}: #{e.message}" - $log.error e.backtrace.join("\n") - $log.error "Cannot output messages with tag '#{tag}'" + log.error "failed to configure sub output #{@subtype}: #{e.message}" + log.error e.backtrace.join("\n") + log.error "Cannot output messages with tag '#{tag}'" output = nil rescue StandardError => e - $log.error "failed to configure/start sub output #{@subtype}: #{e.message}" - $log.error e.backtrace.join("\n") - $log.error "Cannot output messages with tag '#{tag}'" + log.error "failed to configure/start sub output #{@subtype}: #{e.message}" + log.error e.backtrace.join("\n") + log.error "Cannot output messages with tag '#{tag}'" output = nil end output end