class Fluent::ExecOutput
Public Class Methods
new()
click to toggle source
Calls superclass method
Fluent::TimeSlicedOutput.new
# File lib/fluent/plugin/out_exec.rb, line 23 def initialize super require 'tempfile' @localtime = false end
Public Instance Methods
configure(conf)
click to toggle source
Calls superclass method
Fluent::TimeSlicedOutput#configure
# File lib/fluent/plugin/out_exec.rb, line 42 def configure(conf) super @formatter = case @format when :tsv if @keys.empty? raise ConfigError, "keys option is required on exec output for tsv format" end ExecUtil::TSVFormatter.new(@keys) when :json ExecUtil::JSONFormatter.new when :msgpack ExecUtil::MessagePackFormatter.new end if @time_key if @time_format tf = TimeFormatter.new(@time_format, @localtime, @timezone) @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 67 def format(tag, time, record) out = '' if @time_key record[@time_key] = @time_format_proc.call(time) end if @tag_key record[@tag_key] = tag end @formatter.call(record, out) out end
write(chunk)
click to toggle source
# File lib/fluent/plugin/out_exec.rb, line 79 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