Class: Fluent::ExecOutput

Inherits:
TimeSlicedOutput show all
Defined in:
lib/fluent/plugin/out_exec.rb

Constant Summary

Constants included from Configurable

Configurable::CONFIG_TYPE_REGISTRY

Instance Attribute Summary

Attributes inherited from TimeSlicedOutput

#localtime, #time_slicer

Attributes inherited from Output

#router

Attributes included from PluginLoggerMixin

#log

Instance Method Summary collapse

Methods inherited from TimeSlicedOutput

#emit, #enqueue_buffer

Methods inherited from BufferedOutput

#before_shutdown, #calc_retry_wait, #emit, #enqueue_buffer, #flush_secondary, #force_flush, #format_stream, #shutdown, #start, #submit_flush, #try_flush, #write_abort

Methods inherited from Output

#secondary_init, #shutdown, #start

Methods included from PluginLoggerMixin

included

Methods included from PluginId

#plugin_id

Methods included from Configurable

#config, included, lookup_type, register_type

Constructor Details

#initializeExecOutput

Returns a new instance of ExecOutput.



27
28
29
30
# File 'lib/fluent/plugin/out_exec.rb', line 27

def initialize
  super
  @localtime = false
end

Instance Method Details

#configure(conf) ⇒ Object



51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
# File 'lib/fluent/plugin/out_exec.rb', line 51

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) ⇒ Object



76
77
78
79
80
81
82
83
84
85
86
# File 'lib/fluent/plugin/out_exec.rb', line 76

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) ⇒ Object



88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
# File 'lib/fluent/plugin/out_exec.rb', line 88

def write(chunk)
  if chunk.respond_to?(:path)
    prog = "#{@command} #{chunk.path}"
  else
    tmpfile = Tempfile.new("fluent-plugin-exec-")
    tmpfile.binmode
    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