Skip to content

Instantly share code, notes, and snippets.

@kachick
Created January 17, 2014 12:10
Show Gist options
  • Save kachick/8472438 to your computer and use it in GitHub Desktop.
Save kachick/8472438 to your computer and use it in GitHub Desktop.
一度に複数箇所へ同じログ発生させるって需要あると思うんだけど、標準機能では用意されてないのかな。
# 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