Sha256: 93a621463a32daf760c6e2772d64d22e33ab40dd111579f42e90c10c9037d9e8

Contents?: true

Size: 570 Bytes

Versions: 1

Compression:

Stored size: 570 Bytes

Contents

# frozen_string_literal: true

require "pathname"

class Yologga::LogsLifetime
  attr_accessor :pathname

  def initialize(filename)
    self.pathname = Pathname.new(filename)
  end

  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+\z/ && old_enough
        entry.delete
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
yologga-0.3.2 lib/yologga/logs_lifetime.rb