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.



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

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

Instance Method Details

#configure(conf) ⇒ Object



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

def configure(conf)
  super
  @key_names = @key_names.split(',').map do|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
  end
  @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



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

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



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

def shutdown
  super
end

#startObject



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

def start
  super
end

#write(chunk) ⇒ Object



70
71
72
73
74
75
76
77
# File 'lib/fluent/plugin/out_file_sprintf.rb', line 70

def write(chunk)
  if @rotate
    write_file(chunk)
    compress_file if @compress
  else
    write_file_no_rotate(chunk)
  end
end