class Yologga::LogsLifetime

Attributes

pathname[RW]

Public Class Methods

new(filename) click to toggle source
# File lib/yologga/logs_lifetime.rb, line 8
def initialize(filename)
  self.pathname = Pathname.new(filename)
end

Public Instance Methods

call() click to toggle source
# File lib/yologga/logs_lifetime.rb, line 12
def call
  return unless Yologga.logs_lifetime
  entries = Dir.glob(pathname.dirname.join("#{pathname.basename}*")).map { |f| Pathname.new(f) }
  entries.each do |entry|
    next unless entry.file?
    old_enough = entry.mtime < (Time.now - Yologga.logs_lifetime)

    if entry.basename.to_s =~ /\.log\.\d+(?:\.gz)?\z/ && old_enough
      entry.delete
    end
  end
end