Class/Module Index [+]

Quicksearch

Fluent::RecordTransformerFilter

Public Class Methods

new() click to toggle source
# File lib/fluent/plugin/filter_record_transformer.rb, line 23
def initialize
  require 'socket'
  super
end

Public Instance Methods

configure(conf) click to toggle source
# File lib/fluent/plugin/filter_record_transformer.rb, line 33
def configure(conf)
  super

  @map = {}
  # <record></record> directive
  conf.elements.select { |element| element.name == 'record' }.each do |element|
    element.each_pair do |k, v|
      element.has_key?(k) # to suppress unread configuration warning
      @map[k] = parse_value(v)
    end
  end

  if @remove_keys
    @remove_keys = @remove_keys.split(',')
  end

  if @keep_keys
    raise Fluent::ConfigError, "`renew_record` must be true to use `keep_keys`" unless @renew_record
    @keep_keys = @keep_keys.split(',')
  end

  @placeholder_expander =
    if @enable_ruby
      # require utilities which would be used in ruby placeholders
      require 'pathname'
      require 'uri'
      require 'cgi'
      RubyPlaceholderExpander.new(log)
    else
      PlaceholderExpander.new(log)
    end

  @hostname = Socket.gethostname
end
filter_stream(tag, es) click to toggle source
# File lib/fluent/plugin/filter_record_transformer.rb, line 68
def filter_stream(tag, es)
  new_es = MultiEventStream.new
  tag_parts = tag.split('.')
  tag_prefix = tag_prefix(tag_parts)
  tag_suffix = tag_suffix(tag_parts)
  placeholders = {
    'tag' => tag,
    'tag_parts' => tag_parts,
    'tag_prefix' => tag_prefix,
    'tag_suffix' => tag_suffix,
    'hostname' => @hostname,
  }
  last_record = nil
  es.each do |time, record|
    last_record = record # for debug log
    new_record = reform(time, record, placeholders)
    new_es.add(time, new_record)
  end
  new_es
rescue => e
  log.warn "failed to reform records", :error_class => e.class, :error => e.message
  log.warn_backtrace
  log.debug "map:#{@map} record:#{last_record} placeholders:#{placeholders}"
end

[Validate]

Generated with the Darkfish Rdoc Generator 2.