class Lumberjack::Device::SizeRollingLogFile
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.
Attributes
max_size[R]
Public Class Methods
new(path, options = {})
click to toggle source
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.
Calls superclass method
Lumberjack::Device::RollingLogFile::new
# File lib/lumberjack/device/size_rolling_log_file.rb, line 14 def initialize(path, options = {}) @manual = options[:manual] @max_size = options[:max_size] if @max_size.is_a?(String) if @max_size =~ /^(\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
Public Instance Methods
archive_file_suffix()
click to toggle source
# File lib/lumberjack/device/size_rolling_log_file.rb, line 38 def archive_file_suffix next_archive_number.to_s end
roll_file?()
click to toggle source
# File lib/lumberjack/device/size_rolling_log_file.rb, line 42 def roll_file? @manual || stream.stat.size > @max_size rescue SystemCallError false end