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.
Attributes
Public Class Methods
# File lib/lumberjack/device/rolling_log_file.rb, line 13 def initialize(path, options = {}) @path = File.expand_path(path) @keep = options[:keep] super(path, options) @file_inode = stream.lstat.ino rescue nil @@rolls = [] end
Public Instance Methods
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 23 def archive_file_suffix raise NotImplementedError end
Return true
if the file should be rolled.
# File lib/lumberjack/device/rolling_log_file.rb, line 28 def roll_file? raise NotImplementedError end
Protected Instance Methods
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 58 def after_roll end
Private Instance Methods
# File lib/lumberjack/device/rolling_log_file.rb, line 74 def reopen_file old_stream = stream self.stream = File.open(path, 'a', encoding: EXTERNAL_ENCODING) stream.sync = true @file_inode = stream.lstat.ino rescue nil old_stream.close end