Skip to content
logging to file and standard output. require standard library only.
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Type Name Latest commit message Commit time
Failed to load latest commit information.

Gem Version Build Status Downloads Inline docs Code Climate Test Coverage

Sorry. In from version 2 to version 3, changed usage. see also


logging to file and standard output. require standard library only.


  • use standard lib only.
  • like Logger: see usage.
  • enabled or disabled by switching the output of the console and the logfile.


Add this line to your application's Gemfile:

gem 'tee_logger'

And then execute:

$ bundle

Or install it yourself as:

$ gem install tee_logger


let's logging

require 'tee_logger'

# like options(logdev, shift_age, shift_size)
# options default value is
#   logdev     = './tee_logger.log'
#   shift_age  = 0
#   shift_size = 1_048_576
tl =

tl.debug 'hello'
tl.debug(:progname) { 'hello world' }
tl.progname = 'App'
tl.debug 'hello tee_logger'

enable only when specified 'this message is console and logfile' 'this message is console only', :console 'this message is logfile only', :logfile

log meassage indent 'hello'    # => 'hello' 'hello', 0 # => 'hello' 'hello', 2 # => '  hello'

enabling and indent 'this message is console only', 2, :console 'this message is console only', :console, 2

disable console output

tl.disable(:console) 'this message is logfile only'

enable console output

tl.enable(:console) 'this message is logfile and console'

disable logfile output

tl.disable(:logfile) 'this message is consle only'

enable logfile output

tl.enable(:logfile) 'this message is logfile and console'

disable in block

tl.disable(:console) do 'this message is logfile only'
end 'this message is logfile and console'

and others like Logger's

# log_level
tl.debug? # => true  # => true
tl.warn?  # => true
tl.error? # => true
tl.fatal? # => true

tl.level # => 0
tl.level = Logger::INFO
tl.debug 'this message is not logging'

# formatter
tl.formatter # => nil or Proc
tl.formatter =
  proc { |severity, datetime, progname, message| "#{severity}:#{message}" }

# datetime_formatter
tl.datetime_format # => nil or Proc
tl.datetime_format = '%Y%m%d %H%M%S '

include or extend TeeLogger

the log file will be in default of ./tee_logger.log

for casual use

require 'tee_logger'

class YourAwesomeClass
  # define method #logger for your class.
  # log file will be in default of `./tee_logger.log`
  include TeeLogger

  def awesome_method 'this is message is logging and disp console'

module YourAwesomeModule
  # define singleton method .logger for your module.
  # log file will be in default of `./tee_logger.log`
  extend TeeLogger

  def self.awesome_method 'this is message is logging and disp console'

configuration logfile name, progname, level, formatter, and datetime_format.

require 'tee_logger'

# Before extend or include the module, allow the configuration.
# TeeLogger.logdev = 'log1.log'
TeeLogger.configure do |config|
  config.logdev = 'log1.log'
  config.level = Logger::Severity::INFO
  config.progname = 'AwesomeApp'
  config.formatter = proc { |s, t, p, m| "#{s} #{t} #{p} #{m}\n" }
  # config.datetime_format = '%Y%m%d %H%M%S '

class YourAwesomeClass
  include TeeLogger

  def awesome_method 'this message is output `log1.log`'

# reset configuration

# NOTE: sorry, `TeeLogger.logev` is deprecate.
TeeLogger.logdev = 'log2.log'
module YourAwesomeModule
  extend TeeLogger

  def self.awesome_method 'this message is output `log2.log`'


After checking out the repo, run bundle install to install dependencies. Then, run rake rspec to run the tests. You can also run budle exec pry -r ./lib/tee_logger for an interactive prompt that will allow you to experiment.

To install this gem onto your local machine, run bundle exec rake install. To release a new version, update the version number in version.rb, and then run bundle exec rake release, which will create a git tag for the version, push git commits and tags, and push the .gem file to


Bug reports and pull requests are welcome on GitHub at This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the Contributor Covenant code of conduct.


The gem is available as open source under the terms of the MIT License.

You can’t perform that action at this time.