Parent

Class/Module Index [+]

Quicksearch

Fluent::ExecOutput

Public Class Methods

new() click to toggle source
# File lib/fluent/plugin/out_exec.rb, line 24
def initialize
  super
  require 'tempfile'
  @localtime = false
end

Public Instance Methods

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

  @keys = @keys.split(',')

  if @time_key
    if @time_format
      tf = TimeFormatter.new(@time_format, @localtime)
      @time_format_proc = tf.method(:format)
    else
      @time_format_proc = Proc.new {|time| time.to_s }
    end
  end
end
format(tag, time, record) click to toggle source
# File lib/fluent/plugin/out_exec.rb, line 51
def format(tag, time, record)
  out = ''
  last = @keys.length-1
  for i in 0..last
    key = @keys[i]
    if key == @time_key
      out << @time_format_proc.call(time)
    elsif key == @tag_key
      out << tag
    else
      out << record[key].to_s
    end
    out << "\t" if i != last
  end
  out << "\n"
  out
end
write(chunk) click to toggle source
# File lib/fluent/plugin/out_exec.rb, line 69
def write(chunk)
  if chunk.respond_to?(:path)
    prog = "#{@command} #{chunk.path}"
  else
    tmpfile = Tempfile.new("fluent-plugin-exec-")
    chunk.write_to(tmpfile)
    tmpfile.close
    prog = "#{@command} #{tmpfile.path}"
  end

  system(prog)
  ecode = $?.to_i
  tmpfile.delete if tmpfile

  if ecode != 0
    raise "command returns #{ecode}: #{prog}"
  end
end

[Validate]

Generated with the Darkfish Rdoc Generator 2.