Project

birling

0.0
No commit activity in last 3 years
No release in over 3 years
Mostly drop-in replacement for Logger with a more robust log rotation facility
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

 Project Readme

birling

A replacement for Logger that offers more robust handling of log rotation.

The built-in logger supports log rotation on a daily, weekly or monthly basis, but not with more fine-grained control. Birling will allow rotation by hour, by day, or by an arbitrary amount of time expressed in seconds.

Additionally, Birling will automatically remove old log files. These can be pruned off by age, by retaining a minimum number of them, or a combination of both.

Example

The interface is very similar to the built in logger facility that ships with Ruby:

logger = Birling::Logger.new('test.log')

logger.info("Application starting up.")
logger.debug("application_init()")

A short-hand method is available:

logger = Birling.open('test.log')

Log rotation parameters are quite flexible. For example, to retain a maximum of ten hourly logs:

logger = Birling.open(
  'test.log',
  period: :hourly,
  retain_count: 10
)

Alternatively the retention period can be expressed in terms of time where log files that could have been created by this logger which are older than that period will be removed:

logger = Birling.open(
  'test.log',
  period: :hourly,
  retain_period: 10 * 3600
)

The format of the resulting log-file can be adjusted by supplying a formatter. Several arguments passed to the formatter's call method, so a lambda, a module or an object instance could be used for this purpose.

Example:

logger = Birling.open(
  'test.log',
  formatter: -> (severity, time, program, message) { "#{time}> #{message}\n" }
)

Note that the formatter is responsible for introducing any line-feeds into the resulting output stream. This gives the formatter complete control over what is written to the log.

Limitations

The log rotation feature, for reasons that should be obvious, will not work on loggers that are created with an existing file-handle. For example, when using STDOUT the logger will not rotate.

Copyright

Copyright (c) 2011-2019 Scott Tadman, PostageApp Ltd.