# File lib/fluent/plugin/out_file.rb, line 38 def initialize require 'zlib' require 'time' require 'fluent/plugin/file_util' super end
# File lib/fluent/plugin/out_file.rb, line 45 def configure(conf) if path = conf['path'] @path = path end unless @path raise ConfigError, "'path' parameter is required on file output" end if pos = @path.index('*') @path_prefix = @path[0,pos] @path_suffix = @path[pos+1..-1] conf['buffer_path'] ||= "#{@path}" else @path_prefix = @path+"." @path_suffix = ".log" conf['buffer_path'] ||= "#{@path}.*" end test_path = generate_path(Time.now.strftime(@time_slice_format)) unless ::Fluent::FileUtil.writable?(test_path) raise ConfigError, "out_file: `#{test_path}` is not writable" end super @formatter = Plugin.new_formatter(@format) @formatter.configure(conf) @buffer.symlink_path = @symlink_path if @symlink_path end
# File lib/fluent/plugin/out_file.rb, line 76 def format(tag, time, record) @formatter.format(tag, time, record) end
# File lib/fluent/plugin/out_file.rb, line 100 def secondary_init(primary) # don't warn even if primary.class is not FileOutput end
# File lib/fluent/plugin/out_file.rb, line 80 def write(chunk) path = generate_path(chunk.key) FileUtils.mkdir_p File.dirname(path), :mode => DEFAULT_DIR_PERMISSION case @compress when nil File.open(path, "a", DEFAULT_FILE_PERMISSION) {|f| chunk.write_to(f) } when :gz File.open(path, "a", DEFAULT_FILE_PERMISSION) {|f| gz = Zlib::GzipWriter.new(f) chunk.write_to(gz) gz.close } end return path # for test end
# File lib/fluent/plugin/out_file.rb, line 115 def generate_path(time_string) if @append "#{@path_prefix}#{time_string}#{@path_suffix}#{suffix}" else path = nil i = 0 begin path = "#{@path_prefix}#{time_string}_#{i}#{@path_suffix}#{suffix}" i += 1 end while File.exist?(path) path end end
# File lib/fluent/plugin/out_file.rb, line 106 def suffix case @compress when nil '' when :gz ".gz" end end