Class: Lumberjack::Device::RollingLogFile
- Inherits:
-
LogFile
- Object
- Lumberjack::Device
- Writer
- LogFile
- Lumberjack::Device::RollingLogFile
- Defined in:
- lib/lumberjack/device/rolling_log_file.rb
Overview
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.
Direct Known Subclasses
Constant Summary
Constants inherited from Writer
Writer::DEFAULT_ADDITIONAL_LINES_TEMPLATE, Writer::DEFAULT_FIRST_LINE_TEMPLATE
Instance Attribute Summary collapse
-
#keep ⇒ Object
Returns the value of attribute keep.
-
#path ⇒ Object
readonly
Returns the value of attribute path.
Attributes inherited from Writer
Instance Method Summary collapse
-
#archive_file_suffix ⇒ Object
Returns a suffix that will be appended to the file name when it is archived..
-
#initialize(path, options = {}) ⇒ RollingLogFile
constructor
A new instance of RollingLogFile.
-
#roll_file? ⇒ Boolean
Return
true
if the file should be rolled.
Methods inherited from Writer
Methods inherited from Lumberjack::Device
#cleanup_files!, #close, #do_once, #flush, #write
Constructor Details
#initialize(path, options = {}) ⇒ RollingLogFile
Returns a new instance of RollingLogFile.
13 14 15 16 17 18 |
# File 'lib/lumberjack/device/rolling_log_file.rb', line 13 def initialize(path, = {}) @path = File.(path) @keep = [:keep] super(path, ) @file_inode = stream.lstat.ino rescue nil end |
Instance Attribute Details
#keep ⇒ Object
Returns the value of attribute keep.
11 12 13 |
# File 'lib/lumberjack/device/rolling_log_file.rb', line 11 def keep @keep end |
#path ⇒ Object (readonly)
Returns the value of attribute path.
10 11 12 |
# File 'lib/lumberjack/device/rolling_log_file.rb', line 10 def path @path end |
Instance Method Details
#archive_file_suffix ⇒ Object
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.
22 23 24 |
# File 'lib/lumberjack/device/rolling_log_file.rb', line 22 def archive_file_suffix raise NotImplementedError end |
#roll_file? ⇒ Boolean
Return true
if the file should be rolled.
27 28 29 |
# File 'lib/lumberjack/device/rolling_log_file.rb', line 27 def roll_file? raise NotImplementedError end |