Your code is correct for a long-term application.
What happens, you use the code more than once on a specific day.
The first time Ruby starts, it creates the log file "errors.log".
When the day changes, Ruby renames the file to "errors.log.20130217".
- , , ( , ), , , "errors.log.20130217" ,
, "errors.log" , "errors.log.20130217.1"
, .
"foo" "bar", , "foo-errors.log" "bar-errors.log". , , (, , , ).
Ruby, #shift_log_period, ".1". Logger worn #shift_log_period, , , , , .
, :
def shift_log_period(period_end)
postfix = period_end.strftime("%Y%m%d")
age_file = "#{@filename}.#{postfix}"
if FileTest.exist?(age_file)
idx = 0
while idx < 100
idx += 1
age_file = "#{@filename}.#{postfix}.#{idx}"
break unless FileTest.exist?(age_file)
end
end
@dev.close rescue nil
File.rename("#{@filename}", age_file)
@dev = create_logfile(@filename)
return true
(AFAIK) , (, , ), . , .
, logrotate, Tin Man : http://linuxcommand.org/man_pages/logrotate8.html
, logrotate IMHO.