Class: Fluent::FileSprintfOutput

Inherits:
TimeSlicedOutput
  • Object
show all
Defined in:
lib/fluent/plugin/out_file_sprintf.rb

Instance Method Summary collapse

Constructor Details

#initializeFileSprintfOutput

Returns a new instance of FileSprintfOutput.



18
19
20
21
22
23
# File 'lib/fluent/plugin/out_file_sprintf.rb', line 18

def initialize
  super
  require 'zlib'
  require 'ltsv'
  require 'set'
end

Instance Method Details

#configure(conf) ⇒ Object



33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/fluent/plugin/out_file_sprintf.rb', line 33

def configure(conf)
  super
  @key_names = @key_names.split(',').map{|key|
    key = key.strip
    result = ""
    if key == 'time'
      result = "Time.at(time).strftime('#{@time_format}')"
    elsif key == 'tag'
      result = 'tag'
    elsif key == 'ltsv'
      result = 'LTSV.dump(record)'
    elsif key == 'json'
      result = 'record.to_json'
    elsif key == 'msgpack'
      result = 'record.to_msgpack'
    else
      result = "record['" + key + "']"
    end
    result
  }
  @key_names = @key_names.join(',')
  @eval_string = "%Q{#{@format}} % [#{@key_names}]"
  $log.info "format => #{@eval_string}"
  $log.info "flush_interval => #{@flush_interval}"
end

#format(tag, time, record) ⇒ Object



59
60
61
62
63
64
65
66
67
# File 'lib/fluent/plugin/out_file_sprintf.rb', line 59

def format(tag, time, record)
  if @include_tag_key
    record[@tag_key_name] = tag
  end
  if @include_time_key
    record[@time_key_name] = Time.at(time).strftime(@time_format)
  end
  [tag, time, record].to_msgpack
end

#shutdownObject



29
30
31
# File 'lib/fluent/plugin/out_file_sprintf.rb', line 29

def shutdown
  super
end

#startObject



25
26
27
# File 'lib/fluent/plugin/out_file_sprintf.rb', line 25

def start
  super
end

#write(chunk) ⇒ Object



69
70
71
72
# File 'lib/fluent/plugin/out_file_sprintf.rb', line 69

def write(chunk)
  write_file(chunk)
  compress_file
end