Class: Logging::Appenders::RollingFile::DateRoller

Inherits:
Object
  • Object
show all
Defined in:
lib/bixby-common/util/log/logger.rb

Overview

Simple patch to DateRoller which uses the previous day’s date for the rolled filename

oneliner to fix incorrect dates from previously rolled files: ruby -rtime -e ‘`ls .2.log`.split(“n”).each{ |f| f =~ /(2015d+)/; d = $1; dd = (Time.parse(d)-86400).strftime(“%Y%m%d”); File.rename(f, f.gsub(/#d/, dd)) }’

Instance Method Summary collapse

Instance Method Details

#roll_filesObject



34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/bixby-common/util/log/logger.rb', line 34

def roll_files
  return unless @roll and ::File.exist?(@fn_copy)

  # rename the copied log file
  ::File.rename(@fn_copy, (Time.now-86400).strftime(@logname_fmt))

  # prune old log files
  if @keep
    files = Dir.glob(@glob).find_all {|fn| @rgxp =~ fn}
    length = files.length
    if length > @keep
      files.sort {|a,b| b <=> a}.last(length-@keep).each {|fn| ::File.delete fn}
    end
  end

ensure
  @roll = false
end