evanescent
Description
This gem provides an IO like object, that can be used with any logging class (such as Ruby's native Logger). This object will save its input to a file, and allows:
- Hourly or daily rotation.
- Compression of rotated files.
- Removal of old compressed files.
This functionality supplement logging classes, allowing everything related to logging management, to be done within Ruby, without relying on external tools (such as logrotate).
Install
gem install evanescent
This gem uses Semantic Versioning, so you should add to your .gemspec something like:
s.add_runtime_dependency 'evanescent', '~> 1.0'
Please, always check latest available version!
Example
Logger
require 'evanescent'
require 'timecop'
logger = Evanescent.logger(
path: 'test.log',
rotation: :hourly,
keep: '2 hours',
)
logger.class
Timecop.freeze(Time.now)
logger.info 'first message'
Dir.entries('.')
Timecop.freeze(Time.now + 3600)
logger.info 'second message'
Dir.entries('.')
Timecop.freeze(Time.now + 3600)
logger.info 'third message'
Dir.entries('.')
Timecop.freeze(Time.now + 3600)
logger.info 'fourth message'
Dir.entries('.')
Generic usage
Evanescent is an IO like object: it responds to :write and :close:
io = Evanescent.new(
path: 'test.log',
rotation: :hourly,
keep: '2 hours',
)
io.write('message')
io.close
Limitations
Although Evanescent supports mult-thread operation, inter-process locking is not currently implemented, and behavior is unpredicted in this situation.