Project

teelogger

0.0
No commit activity in last 3 years
No release in over 3 years
Mini wrapper around Ruby Logger for logging to multiple destinations.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

~> 1.6
~> 0

Runtime

~> 0.0
 Project Readme

Teelogger

Mini wrapper around Ruby Logger for logging to multiple destinations.

Gem Version Build Status Code Climate Test Coverage

Installation

Add this line to your application's Gemfile:

gem 'teelogger'

And then execute:

$ bundle

Or install it yourself as:

$ gem install teelogger

Usage

Behaves just like Ruby's Logger, and like a hash of String => Logger.

A typical use might be to log to STDOUT, but also to a file:

require 'teelogger'

log = TeeLogger::TeeLogger.new(STDOUT, "filename.log")
log.level = Logger::WARN # applies to all outputs
log.level = "INFO"       # convenience shortcut

By using the instance as a hash, you can also set individual log levels for individual loggers:

require 'teelogger'

log = TeeLogger::TeeLogger.new(STDOUT, "filename.log")
log.each do |name, logger|
  if name.include?("filename.log")
    logger.level = "WARN"
  else
    logger.level = "DEBUG"
  end
end

Unlike the standard Ruby logger, flushing log contents is more deterministic. TeeLogger#flush flushes not only the Ruby buffers of all loggers, but also tries to invoke IO#fsync. In addition, TeeLogger lets you set a flush interval indicating after how many messages logged TeeLogger#flush is to be invoked automatically:

require 'teelogger'

log = TeeLogger::TeeLogger.new(STDOUT, "filename.log")
log.flush_interval = 1                  # flush every line
log["filename.log"].flush_interval = 2  # flush every other line

log.info "first message"  # flushes STDOUT
log.info "second message" # flushes STDOUT and filename.log

Contributing

  1. Fork it ( https://github.com/[my-github-username]/teelogger/fork )
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create a new Pull Request

Shameless Plug

Need software testing services? Contact spriteCloud