Created
October 27, 2015 20:39
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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