Skip to content

Instantly share code, notes, and snippets.

@dcvezzani
Created October 27, 2015 20:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dcvezzani/99c1c5e8965e79b6aa90 to your computer and use it in GitHub Desktop.
Save dcvezzani/99c1c5e8965e79b6aa90 to your computer and use it in GitHub Desktop.
Writes to both STDOUT and the specified file; can include as many IO streams as you want
# Usage example:
#
# log_filename = File.join(log_path, "#{Sinatra::Base.environment.to_s}.log")
# $log_file = File.open(log_filename, 'a+')
#
# STDOUT.sync = true if 'yes' == ENV['API_DEBUG']
# $log_file.sync = true if 'yes' == ENV['API_DEBUG']
#
# require 'logger'
# $logger = Logger.new MultiIO.new(STDOUT, $log_file)
# $logger.level = Logger::DEBUG
#
# ...
#
# #writes to both STDOUT and the specified file
# #can include as many IO streams as you want
#
# $logger.debug("load Mongo")
class MultiIO
def initialize(*targets)
@targets = targets
end
def write(*args)
@targets.each {|t| t.write(*args)}
end
def close
@targets.each(&:close)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment