class Lumberjack::Device::RollingLogFile

This is an abstract class for a device that appends entries to a file and periodically archives the existing file and starts a one. Subclasses must implement the roll_file? and archive_file_suffix methods.

The :keep option can be used to specify a maximum number of rolled log files to keep. Older files will be deleted based on the time they were created. The default is to keep all files.

The :min_roll_check option can be used to specify the number of seconds between checking the file to determine if it needs to be rolled. The default is to check at most once per second.

Attributes

keep[RW]
path[R]

Public Class Methods

new(path, options = {}) click to toggle source
Calls superclass method Lumberjack::Device::LogFile::new
# File lib/lumberjack/device/rolling_log_file.rb, line 18
def initialize(path, options = {})
  @path = File.expand_path(path)
  @keep = options[:keep]
  super(path, options)
  @file_inode = begin
                  stream.lstat.ino
                rescue
                  nil
                end
  @@rolls = []
  @next_stat_check = Time.now.to_f
  @min_roll_check = (options[:min_roll_check] || 1.0).to_f
end

Public Instance Methods

archive_file_suffix() click to toggle source

Returns a suffix that will be appended to the file name when it is archived.. The suffix should change after it is time to roll the file. The log file will be renamed when it is rolled.

# File lib/lumberjack/device/rolling_log_file.rb, line 34
def archive_file_suffix
  raise NotImplementedError
end
roll_file?() click to toggle source

Return true if the file should be rolled.

# File lib/lumberjack/device/rolling_log_file.rb, line 39
def roll_file?
  raise NotImplementedError
end

Protected Instance Methods

after_roll() click to toggle source

This method will be called after a file has been rolled. Subclasses can implement code to reset the state of the device. This method is thread safe.

# File lib/lumberjack/device/rolling_log_file.rb, line 73
def after_roll
end

Private Instance Methods

reopen_file() click to toggle source
# File lib/lumberjack/device/rolling_log_file.rb, line 96
def reopen_file
  old_stream = stream
  new_stream = File.open(path, "a", encoding: EXTERNAL_ENCODING)
  new_stream.sync = true if buffer_size > 0
  @file_inode = begin
                  new_stream.lstat.ino
                rescue
                  nil
                end
  self.stream = new_stream
  old_stream.close
end