Class: Lumberjack::Device::SizeRollingLogFile
- Inherits:
-
RollingLogFile
- Object
- Lumberjack::Device
- Writer
- LogFile
- RollingLogFile
- Lumberjack::Device::SizeRollingLogFile
- Defined in:
- lib/lumberjack/device/size_rolling_log_file.rb
Overview
This is a log device that appends entries to a file and rolls the file when it reaches a specified size threshold. When a file is rolled, it will have an number extension appended to the file name. For example, if the log file is named production.log, the first time it is rolled it will be renamed production.log.1, then production.log.2, etc.
Constant Summary
Constants inherited from Writer
Writer::DEFAULT_ADDITIONAL_LINES_TEMPLATE, Writer::DEFAULT_FIRST_LINE_TEMPLATE
Instance Attribute Summary collapse
-
#max_size ⇒ Object
readonly
Returns the value of attribute max_size.
Attributes inherited from RollingLogFile
Attributes inherited from LogFile
Attributes inherited from Writer
Instance Method Summary collapse
- #archive_file_suffix ⇒ Object
-
#initialize(path, options = {}) ⇒ SizeRollingLogFile
constructor
Create an new log device to the specified file.
- #roll_file? ⇒ Boolean
Methods inherited from RollingLogFile
Methods inherited from Writer
Methods inherited from Lumberjack::Device
#cleanup_files!, #close, #do_once, #flush, #write
Constructor Details
#initialize(path, options = {}) ⇒ SizeRollingLogFile
Create an new log device to the specified file. The maximum size of the log file is specified with the :max_size
option. The unit can also be specified: “32K”, “100M”, “2G” are all valid.
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/lumberjack/device/size_rolling_log_file.rb', line 12 def initialize(path, = {}) @manual = [:manual] @max_size = [:max_size] if @max_size.is_a?(String) if @max_size.match(/^(\d+(\.\d+)?)([KMG])?$/i) @max_size = $~[1].to_f units = $~[3].to_s.upcase case units when "K" @max_size *= 1024 when "M" @max_size *= 1024 ** 2 when "G" @max_size *= 1024 ** 3 end @max_size = @max_size.round else raise ArgumentError.new("illegal value for :max_size (#{@max_size})") end end super end |
Instance Attribute Details
#max_size ⇒ Object (readonly)
Returns the value of attribute max_size.
8 9 10 |
# File 'lib/lumberjack/device/size_rolling_log_file.rb', line 8 def max_size @max_size end |
Instance Method Details
#archive_file_suffix ⇒ Object
36 37 38 |
# File 'lib/lumberjack/device/size_rolling_log_file.rb', line 36 def archive_file_suffix next_archive_number.to_s end |
#roll_file? ⇒ Boolean
40 41 42 43 44 |
# File 'lib/lumberjack/device/size_rolling_log_file.rb', line 40 def roll_file? @manual || stream.stat.size > @max_size rescue SystemCallError => e false end |