Method: Logging::Appenders::File#initialize

Defined in:
lib/gems/logging-0.9.4/lib/logging/appenders/file.rb

#initialize(name, opts = {}) ⇒ File

call-seq:

File.new( name, :filename => 'file' )
File.new( name, :filename => 'file', :truncate => true )
File.new( name, :filename => 'file', :layout => layout )

Creates a new File Appender that will use the given filename as the logging destination. If the file does not already exist it will be created. If the :truncate option is set to true then the file will be truncated before writing begins; otherwise, log messages will be appened to the file.

Raises:

  • (ArgumentError)


42
43
44
45
46
47
48
49
# File 'lib/gems/logging-0.9.4/lib/logging/appenders/file.rb', line 42

def initialize( name, opts = {} )
  @fn = opts.getopt(:filename, name)
  raise ArgumentError, 'no filename was given' if @fn.nil?
  self.class.assert_valid_logfile(@fn)
  mode = opts.getopt(:truncate) ? 'w' : 'a'

  super(name, ::File.new(@fn, mode), opts)
end