Parent

Logging::Appenders::File

This class provides an Appender that can write to a File.

Public Class Methods

assert_valid_logfile( filename ) => true click to toggle source

Asserts that the given filename can be used as a log file by ensuring that if the file exists it is a regular file and it is writable. If the file does not exist, then the directory is checked to see if it is writable.

An ArgumentError is raised if any of these assertions fail.

    # File lib/logging/appenders/file.rb, line 25
25:     def self.assert_valid_logfile( fn )
26:       if ::File.exist?(fn)
27:         if not ::File.file?(fn)
28:           raise ArgumentError, "#{fn} is not a regular file"
29:         elsif not ::File.writable?(fn)
30:           raise ArgumentError, "#{fn} is not writeable"
31:         end
32:       elsif not ::File.writable?(::File.dirname(fn))
33:         raise ArgumentError, "#{::File.dirname(fn)} is not writable"
34:       end
35:       true
36:     end
new( name, :filename => 'file', :layout => layout ) click to toggle source

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.

    # File lib/logging/appenders/file.rb, line 49
49:     def initialize( name, opts = {} )
50:       @fn = opts.getopt(:filename, name)
51:       raise ArgumentError, 'no filename was given' if @fn.nil?
52: 
53:       @fn = ::File.expand_path(@fn)
54:       self.class.assert_valid_logfile(@fn)
55:       @mode = opts.getopt(:truncate) ? 'w' : 'a'
56: 
57:       super(name, ::File.new(@fn, @mode), opts)
58:     end

Public Instance Methods

filename() click to toggle source

Returns the path to the logfile.

    # File lib/logging/appenders/file.rb, line 62
62:     def filename() @fn.dup end
reopen() click to toggle source

Reopen the connection to the underlying logging destination. If the connection is currently closed then it will be opened. If the connection is currently open then it will be closed and immediately opened.

    # File lib/logging/appenders/file.rb, line 68
68:     def reopen
69:       @mutex.synchronize {
70:         if defined? @io and @io
71:           flush
72:           @io.close rescue nil
73:         end
74:         @io = ::File.new(@fn, @mode)
75:       }
76:       super
77:       self
78:     end

Disabled; run with --debug to generate this.

[Validate]

Generated with the Darkfish Rdoc Generator 1.1.6.