Class: Yologga::LogsLifetime
- Inherits:
-
Object
- Object
- Yologga::LogsLifetime
- Defined in:
- lib/yologga/logs_lifetime.rb
Instance Attribute Summary collapse
-
#pathname ⇒ Object
Returns the value of attribute pathname.
Instance Method Summary collapse
- #call ⇒ Object
-
#initialize(filename) ⇒ LogsLifetime
constructor
A new instance of LogsLifetime.
Constructor Details
#initialize(filename) ⇒ LogsLifetime
Returns a new instance of LogsLifetime.
8 9 10 |
# File 'lib/yologga/logs_lifetime.rb', line 8 def initialize(filename) self.pathname = Pathname.new(filename) end |
Instance Attribute Details
#pathname ⇒ Object
Returns the value of attribute pathname.
6 7 8 |
# File 'lib/yologga/logs_lifetime.rb', line 6 def pathname @pathname end |
Instance Method Details
#call ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 23 |
# 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 |