0.0
Low commit activity in last 3 years
A long-lived project that still receives updates
Tie log (or other file) rotation to the (un-scheduled?) execution of code. The raison d'étre for this gem is that I'm too lazy to clear out test and development logs manually and am too anal-retentive to be happy with large log files accumulating in my various project directories.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

>= 0
~> 3.0
~> 13.0
 Project Readme

LazyRotator

Tie log (or other file) rotation to the (un-scheduled?) execution of code. The raison d'étre for this gem is that I'm too lazy to clear out test and development logs manually and am too anal-retentive to be happy with large log files accumulating in my various project directories.

On those rare occasions when I do want to look at a log file in my development environment, I don't want to waste time skipping past megabytes of older log entries. On the other hand, I might have restarted my app server or run tests (maybe a different set) again before deciding to look at the logs, so I don't want to simply truncate the log files on each run - keeping a few very recent files around seems to be a useful compromise.

Installation

Add this line to your application's Gemfile:

gem 'lazy_rotator', group: %i(development test)

And then execute:

$ bundle

Or install it yourself as:

$ gem install lazy_rotator

Usage

For a Rails app, add the following to config/application.rb:

if Kernel.const_defined?(:LazyRotator) && (Rails.env.test? || Rails.env.development?)
  log_file = File.expand_path("../log/#{Rails.env}.log", __dir__)
  LazyRotator.rotate log_file
end

Note: you will probably need to update your .gitignore file to match /log/*.log* - that trailing * will make sure the rotated log files are ignored.

Set the number of copies to keep (the default is 5):

LazyRotator.rotate 'path/to/log', 20

Contributing

Bug reports and pull requests are welcome.