Sha256: b14d577d52a0ea89b0066aede095f0895d14e79265913d8acb3e7143aa9d05f1

Contents?: true

Size: 790 Bytes

Versions: 4

Compression:

Stored size: 790 Bytes

Contents

module Madvertise
  module Logging

    ##
    # MultiLogger is a simple class for multiplexing ImprovedLogger objects. It
    # support attach/detach to send messages to any number of loggers.

    class MultiLogger
      def initialize(*loggers)
        @loggers = loggers
      end

      # Attach an ImprovedLogger object.
      def attach(logger)
        logger.token = @loggers.first.token rescue nil
        @loggers << logger
      end

      # Detach an ImprovedLogger object.
      def detach(logger)
        @loggers.delete(logger)
      end

      # Delegate all method calls to all attached loggers.
      #
      # @private
      def method_missing(name, *args)
        @loggers.map do |logger|
          logger.send(name, *args)
        end.first
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
madvertise-logging-0.8.0 lib/madvertise/logging/multi_logger.rb
madvertise-logging-0.7.3 lib/madvertise/logging/multi_logger.rb
madvertise-logging-0.7.2 lib/madvertise/logging/multi_logger.rb
madvertise-logging-0.7.1 lib/madvertise/logging/multi_logger.rb