Class: Log4r::FileOutputter

### Home Classes Methods

### In Files

- lib/log4r/outputter/fileoutputter.rb

### Parent

IOOutputter

### Methods

- ::new

### Files

- GDC
- MDC
- NDC
- configurator
- emailoutputter
- formatter
- log4jxmlformatter
- log4r
- logger
- logserver
- outputter
- patternformatter
- scribeoutputter
- syslogoutputter
- win32eventoutputter
- yamlconfigurator

### Class/Module Index

Quicksearch

- Log4r
- Log4r::BasicFormatter
- Log4r::ConfigError
- Log4r::Configurator
- Log4r::DateFileOutputter
- Log4r::DefaultFormatter
- Log4r::EmailOutputter
- Log4r::FileOutputter
- Log4r::Formatter
- Log4r::GDC
- Log4r::IOOutputter
- Log4r::Log4jXmlFormatter
- Log4r::Log4rTools
- Log4r::LogEvent
- Log4r::LogServer
- Log4r::Logger
- Log4r::MDC
- Log4r::NDC
- Log4r::ObjectFormatter
- Log4r::Outputter
- Log4r::PatternFormatter
- Log4r::RemoteOutputter
- Log4r::RollingFileOutputter
- Log4r::RootLogger
- Log4r::ScribeOutputter
- Log4r::SimpleFormatter
- Log4r::StderrOutputter
- Log4r::StdoutOutputter
- Log4r::SyslogOutputter
- Log4r::UDPOutputter
- Log4r::YamlConfigurator
- REXML
- Object

No matching classes.

# Log4r::FileOutputter

Convenience wrapper for File. Additional hash arguments are:

`:filename`

  Name of the file to log to.

`:trunc`

  Truncate the file?

### Attributes

filename[R]
trunc[R]

### Public Class Methods

new(_name, hash={}) click to toggle source

    # File lib/log4r/outputter/fileoutputter.rb, line 16
    def initialize(_name, hash={})
      super(_name, nil, hash)

      @trunc = Log4rTools.decode_bool(hash, :trunc, false)
      _filename = (hash[:filename] or hash['filename'])
      @create = Log4rTools.decode_bool(hash, :create, true)

      if _filename.class != String
        raise TypeError, "Argument 'filename' must be a String", caller
      end

      # file validation
      if FileTest.exist?( _filename )
        if not FileTest.file?( _filename )
          raise StandardError, "'#{_filename}' is not a regular file", caller
        elsif not FileTest.writable?( _filename )
          raise StandardError, "'#{_filename}' is not writable!", caller
        end
      else # ensure directory is writable
        dir = File.dirname( _filename )
        if not FileTest.writable?( dir )
          raise StandardError, "'#{dir}' is not writable!"
        end
      end

      @filename = _filename
      if ( @create == true ) then
        @out = File.new(@filename, (@trunc ? "wb" : "ab"))
        Logger.log_internal {
          "FileOutputter '#{@name}' writing to #{@filename}"
        }
      else
        Logger.log_internal {
          "FileOutputter '#{@name}' called with :create == false, #{@filename}"
        }
      end
    end

[Validate]

Generated with the Darkfish Rdoc Generator 2.