Created
January 17, 2014 12:10
-
-
Save kachick/8472438 to your computer and use it in GitHub Desktop.
一度に複数箇所へ同じログ発生させるって需要あると思うんだけど、標準機能では用意されてないのかな。
This file contains hidden or 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
# coding: us-ascii | |
require 'logger' | |
class MultiLogger | |
def initialize(*destinations) | |
@destinations = destinations.map { |dst| Logger.new dst } | |
end | |
Logger.instance_methods.each do |meth| | |
define_method meth do |*args, &block| | |
@destinations.each { |dst| dst.__send__ meth, *args, &block } | |
end | |
end | |
end | |
MultiLogger.new $stdout, 'logfile.log' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment