Class: Log4r::RollingFileOutputter

### Home Classes Methods

### In Files

- lib/log4r/outputter/rollingfileoutputter.rb

### Parent

Log4r::FileOutputter

### 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::RollingFileOutputter

RollingFileOutputter - subclass of FileOutputter that rolls files on size or time. So, given a filename of "error.log", the first log file will be "error000001.log". When its check condition is exceeded, it'll create and log to "error000002.log", etc.

Additional hash arguments are:

`:maxsize`

  Maximum size of the file in bytes.

`:maxtime`

  Maximum age of the file in seconds.

`:max_backups`

  Maxium number of prior log files to maintain. If max_backups is a positive number,

    then each time a roll happens, RollingFileOutputter will delete the oldest backup log files in excess
    of this number (if any).  So, if max_backups is 10, then a maximum of 11 files will be maintained (the current
    log, plus 10 backups). If max_backups is 0, no backups will be kept. If it is negative (the default),
    there will be no limit on the number of files created. Note that the sequence numbers will continue to escalate;
    old sequence numbers are not reused.

`:trunc`

  If true, deletes ALL existing log files (based on :filename) upon initialization,

    and the sequence numbering will start over at 000001. Otherwise continues logging where it left off
    last time (i.e. either to the file with the highest sequence number, or a new file, as appropriate).

### Attributes

current_sequence_number[R]
max_backups[R]
maxsize[R]
maxtime[R]
start_time[R]

### Public Class Methods

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

    # File lib/log4r/outputter/rollingfileoutputter.rb, line 33
    def initialize(_name, hash={})
      super( _name, hash.merge({:create => false}) )
      if hash.has_key?(:maxsize) || hash.has_key?('maxsize')
        _maxsize = (hash[:maxsize] or hash['maxsize']).to_i
        if _maxsize.class != Fixnum
          raise TypeError, "Argument 'maxsize' must be an Fixnum", caller
        end
        if _maxsize == 0
          raise TypeError, "Argument 'maxsize' must be > 0", caller
        end
        @maxsize = _maxsize
      end
      if hash.has_key?(:maxtime) || hash.has_key?('maxtime')
        _maxtime = (hash[:maxtime] or hash['maxtime']).to_i
        if _maxtime.class != Fixnum
          raise TypeError, "Argument 'maxtime' must be an Fixnum", caller
        end
        if _maxtime == 0
          raise TypeError, "Argument 'maxtime' must be > 0", caller
        end
        @maxtime = _maxtime
      end
      if hash.has_key?(:max_backups) || hash.has_key?('max_backups')
        _max_backups = (hash[:max_backups] or hash['max_backups']).to_i
        if _max_backups.class != Fixnum
          raise TypeError, "Argument 'max_backups' must be an Fixnum", caller
        end
        @max_backups = _max_backups
      else
        @max_backups = -1
      end
      # @filename starts out as the file (including path) provided by the user, e.g. "\usr\logs\error.log".
      #   It will get assigned the current log file (including sequence number)
      # @log_dir is the directory in which we'll log, e.g. "\usr\logs"
      # @file_extension is the file's extension (if any) including any period, e.g. ".log"
      # @core_file_name is the part of the log file's name, sans sequence digits or extension, e.g. "error"
      @log_dir = File.dirname(@filename)
      @file_extension = File.extname(@filename)   # Note: the File API doc comment states that this doesn't include the period, but its examples and behavior do include it. We'll depend on the latter.
      @core_file_name = File.basename(@filename, @file_extension)
      if (@trunc)
        purge_log_files(0)
      end
      @current_sequence_number = get_current_sequence_number()
      makeNewFilename
      # Now @filename points to a properly sequenced filename, which may or may not yet exist.
      open_log_file('a')

      # Note: it's possible we're already in excess of our time or size constraint for the current file;
      # no worries -- if a new file needs to be started, it'll happen during the write() call.
    end

[Validate]

Generated with the Darkfish Rdoc Generator 2.