class Fluent::FileOutput
Constants
- SUPPORTED_COMPRESS
Public Class Methods
new()
click to toggle source
Calls superclass method
Fluent::TimeSlicedOutput.new
# File lib/fluent/plugin/out_file.rb, line 39 def initialize require 'zlib' require 'time' super end
Public Instance Methods
configure(conf)
click to toggle source
Calls superclass method
Fluent::TimeSlicedOutput#configure
# 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 super @formatter = Plugin.new_formatter(@format) @formatter.configure(conf) @buffer.symlink_path = @symlink_path if @symlink_path end
format(tag, time, record)
click to toggle source
# File lib/fluent/plugin/out_file.rb, line 71 def format(tag, time, record) @formatter.format(tag, time, record) end
secondary_init(primary)
click to toggle source
# File lib/fluent/plugin/out_file.rb, line 95 def secondary_init(primary) # don't warn even if primary.class is not FileOutput end
write(chunk)
click to toggle source
# File lib/fluent/plugin/out_file.rb, line 75 def write(chunk) path = generate_path(chunk) 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
Private Instance Methods
generate_path(chunk)
click to toggle source
# File lib/fluent/plugin/out_file.rb, line 101 def generate_path(chunk) case @compress when nil suffix = '' when :gz suffix = ".gz" end if @append "#{@path_prefix}#{chunk.key}#{@path_suffix}#{suffix}" else path = nil i = 0 begin path = "#{@path_prefix}#{chunk.key}_#{i}#{@path_suffix}#{suffix}" i += 1 end while File.exist?(path) path end end