Method: Fluent::Plugin::SecondaryFileOutput#write

Defined in:
lib/fluent/plugin/out_secondary_file.rb

#write(chunk) ⇒ Object



70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
# File 'lib/fluent/plugin/out_secondary_file.rb', line 70

def write(chunk)
  path_without_suffix = extract_placeholders(@path_without_suffix, chunk)
  generate_path(path_without_suffix) do |path|
    FileUtils.mkdir_p File.dirname(path), mode: @dir_perm

    case @compress
    when :text
      File.open(path, "ab", @file_perm) {|f|
        f.flock(File::LOCK_EX)
        chunk.write_to(f)
      }
    when :gzip
      File.open(path, "ab", @file_perm) {|f|
        f.flock(File::LOCK_EX)
        gz = Zlib::GzipWriter.new(f)
        chunk.write_to(gz)
        gz.close
      }
    end
  end
end