The Rails logger has an auto_flushing method. This delays logging until the number of entries is the same as everything that was set. This has been around with Rails 2 and is designed to speed things up by stopping persistent writing to disk at boot time.
This is great in most cases, but we have short work tasks that never last long enough to get past the flash - all errors disappear.
Is there a way to ensure that the log is cleared when the process dies?
EDIT
In the end I did it (but it is very verbose)
af = Rails.logger.auto_flushing Rails.logger.auto_flushing = true Rails.logger.error "my message" Rails.logger.auto_flushing = af
This causes the message to exit, but after that it automatically shuts down.
For a truly complete solution, put this in the initializer:
class << Rails.logger def flush_error( message ) Rails.logger.error message Rails.logger.flush end end
Then just use the method as and when ...
source share