FileOutputter
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:
Maximum size of the file in bytes.
Maximum age of the file in seconds.
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.
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).
# 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
Generated with the Darkfish Rdoc Generator 2.