Last active
August 29, 2015 14:27
-
-
Save leonardoeloy/1ac950613f0d1f19cc9d to your computer and use it in GitHub Desktop.
MultiLogger with Ruby
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
module Whatever | |
class MultiLogger | |
def initialize(*loggers) | |
@loggers = loggers | |
end | |
def method_missing(method, *args, &block) | |
@loggers.each do |logger| | |
logger_method = logger.method(method) | |
logger_method.call *args, &block | |
end | |
end | |
def respond_to_missing?(method, include_private = false) | |
true | |
end | |
end | |
def self.logger | |
@@multilogger ||= MultiLogger.new Logger.new('file.log'), Logger.new(STDOUT) | |
end | |
end | |
# Whatever.logger.info "Test" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment