Method: Logging::Appenders::File#initialize
- Defined in:
- 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 appended to the file.
45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/logging/appenders/file.rb', line 45 def initialize( name, opts = {} ) @filename = opts.fetch(:filename, name) raise ArgumentError, 'no filename was given' if @filename.nil? @filename = ::File.(@filename).freeze self.class.assert_valid_logfile(@filename) self.encoding = opts.fetch(:encoding, self.encoding) io = open_file super(name, io, opts) truncate if opts.fetch(:truncate, false) end |