Sha256: fa24fc37e541eb6e97fda3934fd2349d175064147c10979101bc52f3c5889a7b

Contents?: true

Size: 579 Bytes

Versions: 1

Compression:

Stored size: 579 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+(?:\.gz)?\z/ && old_enough
        entry.delete
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

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