Project

evanescent

0.0
Repository is archived
No commit activity in last 3 years
No release in over 3 years
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: rotation by time / date, compression of old files and removal of old compressed files. Its purpuse is to supplement logging classes, allowing everything related to logging management, to be done within Ruby, without relying on external tools (such as logrotate).
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

~> 4.6, ~> 4.6.4
>= 10.4.2, ~> 10.4
~> 3.3
~> 0.10
~> 0.8

Runtime

>= 0.10.6, ~> 0.10
 Project Readme

evanescent

Build Status Gem Version GitHub issues GitHub license Downloads

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 # => Logger

# Within first hour, only test.log will exist.
Timecop.freeze(Time.now)
logger.info 'first message'
Dir.entries('.') # => [".", "..", "test.log"]

# One hour later, rotation and compression will happen.
Timecop.freeze(Time.now + 3600)
logger.info 'second message'
Dir.entries('.') # => [".", "..", "test.log", "test.log.2015122315.gz"]

# Another hour later, we'll have 2 compressed files.
Timecop.freeze(Time.now + 3600)
logger.info 'third message'
Dir.entries('.') # => [".", "..", "test.log", "test.log.2015122315.gz", "test.log.2015122316.gz"]

# At last, after keep period, old compressed files are purged.
Timecop.freeze(Time.now + 3600)
logger.info 'fourth message'
Dir.entries('.') # => [".", "..", "test.log", "test.log.2015122316.gz", "test.log.2015122317.gz"]

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') # writes message to test.log
io.close

Limitations

Although Evanescent supports mult-thread operation, inter-process locking is not currently implemented, and behavior is unpredicted in this situation.