Parent

Class/Module Index [+]

Quicksearch

Fluent::FileOutput

Constants

SUPPORTED_COMPRESS

Public Class Methods

new() click to toggle source
# File lib/fluent/plugin/out_file.rb, line 41
def initialize
  require 'zlib'
  require 'time'
  super
end

Public Instance Methods

configure(conf) click to toggle source
# File lib/fluent/plugin/out_file.rb, line 47
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

  @timef = TimeFormatter.new(@time_format, @localtime)
end
format(tag, time, record) click to toggle source
# File lib/fluent/plugin/out_file.rb, line 70
def format(tag, time, record)
  time_str = @timef.format(time)
  "#{time_str}\t#{tag}\t#{Yajl.dump(record)}\n"
end
secondary_init(primary) click to toggle source
# File lib/fluent/plugin/out_file.rb, line 104
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)
  case @compress
  when nil
    suffix = ''
  when :gz
    suffix = ".gz"
  end

  i = 0
  begin
    path = "#{@path_prefix}#{chunk.key}_#{i}#{@path_suffix}#{suffix}"
    i += 1
  end while File.exist?(path)
  FileUtils.mkdir_p File.dirname(path)

  case @compress
  when nil
    File.open(path, "a", DEFAULT_FILE_PERMISSION) {|f|
      chunk.write_to(f)
    }
  when :gz
    Zlib::GzipWriter.open(path) {|f|
      chunk.write_to(f)
    }
  end

  return path  # for test
end

[Validate]

Generated with the Darkfish Rdoc Generator 2.