module Fluent::PluginHelper::Extract

Public Class Methods

included(mod) click to toggle source
# File lib/fluent/plugin_helper/extract.rb, line 63
def self.included(mod)
  mod.include ExtractParams
end
new() click to toggle source
Calls superclass method
# File lib/fluent/plugin_helper/extract.rb, line 67
def initialize
  super
  @_extract_enabled = false
  @_extract_tag_key = nil
  @_extract_keep_tag_key = nil
  @_extract_time_key = nil
  @_extract_keep_time_key = nil
  @_extract_time_parser = nil
end

Public Instance Methods

configure(conf) click to toggle source
Calls superclass method
# File lib/fluent/plugin_helper/extract.rb, line 77
def configure(conf)
  super

  if @extract_config
    @_extract_tag_key = @extract_config.tag_key
    @_extract_keep_tag_key = @extract_config.keep_tag_key
    @_extract_time_key = @extract_config.time_key
    if @_extract_time_key
      @_extract_keep_time_key = @extract_config.keep_time_key
      @_extract_time_parser = case @extract_config.time_type
                              when :float then Fluent::NumericTimeParser.new(:float)
                              when :unixtime then Fluent::NumericTimeParser.new(:unixtime)
                              else
                                localtime = @extract_config.localtime && !@extract_config.utc
                                Fluent::TimeParser.new(@extract_config.time_format, localtime, @extract_config.timezone)
                              end
    else
      if @extract_config.time_format
        log.warn "'time_format' specified without 'time_key', will be ignored"
      end
    end

    @_extract_enabled = @_extract_tag_key || @_extract_time_key
  end
end
extract_tag_from_record(record) click to toggle source
# File lib/fluent/plugin_helper/extract.rb, line 24
def extract_tag_from_record(record)
  return nil unless @_extract_enabled

  if @_extract_tag_key && record.has_key?(@_extract_tag_key)
    v = @_extract_keep_tag_key ? record[@_extract_tag_key] : record.delete(@_extract_tag_key)
    return v.to_s
  end

  nil
end
extract_time_from_record(record) click to toggle source
# File lib/fluent/plugin_helper/extract.rb, line 35
def extract_time_from_record(record)
  return nil unless @_extract_enabled

  if @_extract_time_key && record.has_key?(@_extract_time_key)
    v = @_extract_keep_time_key ? record[@_extract_time_key] : record.delete(@_extract_time_key)
    return @_extract_time_parser.call(v)
  end

  nil
end