In: |
logger.rb
|
Parent: | Object |
SYNOPSIS
Logger::LogDev.new(name, opt = {})
ARGS
log String as filename of logging. or IO as logging device(i.e. STDERR). opt Hash of options.
DESCRIPTION
Log device class. Output and shifting of log. When a String was given, LogDevice opens the file and set sync = true.
OPTIONS
:shift_age An Integer Num of files you want to keep aged logs. 'daily' Daily shifting. 'weekly' Weekly shifting (Shift every monday.) 'monthly' Monthly shifting (Shift every 1th day.) :shift_size Shift size threshold when :shift_age is an integer. Otherwise (like 'daily'), it is ignored.
# File logger.rb, line 323 def initialize(log = nil, opt = {}) @dev = @filename = @shift_age = @shift_size = nil if log.respond_to?(:write) and log.respond_to?(:close) @dev = log elsif log.is_a?(String) @dev = open_logfile(log) @dev.sync = true @filename = log @shift_age = opt[:shift_age] || 7 @shift_size = opt[:shift_size] || 1048576 else raise ArgumentError.new("Wrong argument: #{ log } for log.") end end
SYNOPSIS
Logger::LogDev#write(message)
ARGS
message Message to be logged.
DESCRIPTION
Log a message. If needed, the log device is aged and the new device is prepared. Log device is not locked. Append open does not need to lock file but on the OS which supports multi I/O, records possibly be mixed.
# File logger.rb, line 350 def write(message) if shift_log? begin shift_log rescue raise Logger::ShiftingError.new("Shifting failed. #{$!}") end end @dev.write(message) end