Mini wrapper around Ruby Logger for logging to multiple destinations.
Add this line to your application's Gemfile:
And then execute:
Or install it yourself as:
$ gem install teelogger
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.
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
- Fork it ( https://github.com/[my-github-username]/teelogger/fork )
- Create your feature branch (
git checkout -b my-new-feature)
- Commit your changes (
git commit -am 'Add some feature')
- Push to the branch (
git push origin my-new-feature)
- Create a new Pull Request
Need software testing services? Contact spriteCloud