Sha256: 244e836da0c8b578a80830dd7e820cac5f4ce4b145a3d5ec7d9e83b43ef9587f

Contents?: true

Size: 1.61 KB

Versions: 68

Compression:

Stored size: 1.61 KB

Contents

# encoding: utf-8

# You can use arbitrary logger which responds to #debug, #info, #error and #fatal methods, so for example the logger from standard library will work fine:
#
# AMQ::Client.logging = true
# AMQ::Client.logger  = MyLogger.new(STDERR)
#
# AMQ::Client.logger defaults to a new instance of Ruby stdlib logger.
#
# If you want to be able to log messages just from specified classes or even instances, just make the instance respond to #logging and set it to desired value. So for example <tt>Queue.class_eval { def logging; true; end }</tt> will turn on logging for the whole Queue class whereas <tt>queue = Queue.new; def queue.logging; false; end</tt> will disable logging for given Queue instance.

module AMQ
  module Client
    module Logging
      def self.included(klass)
        unless klass.method_defined?(:client)
          raise NotImplementedError.new("Class #{klass} has to provide #client method!")
        end
      end

      def self.logging
        @logging ||= false
      end

      def self.logging=(boolean)
        @logging = boolean
      end

      REQUIRED_METHODS = [:debug, :info, :error, :fatal].freeze

      def debug(message)
        log(:debug, message)
      end

      def info(message)
        log(:info, message)
      end

      def error(message)
        log(:error, message)
      end

      def fatal(message)
        log(:fatal, message)
      end

      protected
      def log(method, message)
        if self.respond_to?(:logging) ? self.logging : AMQ::Client::Logging.logging
          self.client.logger.__send__(method, message)
          message
        end
      end
    end
  end
end

Version data entries

68 entries across 68 versions & 1 rubygems

Version Path
amq-client-0.9.0 lib/amq/client/logging.rb
amq-client-0.9.0.pre2 lib/amq/client/logging.rb
amq-client-0.9.0.pre1 lib/amq/client/logging.rb
amq-client-0.8.7 lib/amq/client/logging.rb
amq-client-0.8.7.pre1 lib/amq/client/logging.rb
amq-client-0.8.6 lib/amq/client/logging.rb
amq-client-0.8.5 lib/amq/client/logging.rb
amq-client-0.8.4 lib/amq/client/logging.rb
amq-client-0.8.3 lib/amq/client/logging.rb
amq-client-0.8.2 lib/amq/client/logging.rb
amq-client-0.8.1 lib/amq/client/logging.rb
amq-client-0.8.0 lib/amq/client/logging.rb
amq-client-0.7.0.alpha35 lib/amq/client/logging.rb
amq-client-0.7.0.alpha34 lib/amq/client/logging.rb
amq-client-0.7.0.alpha33 lib/amq/client/logging.rb
amq-client-0.7.0.alpha32 lib/amq/client/logging.rb
amq-client-0.7.0.alpha31 lib/amq/client/logging.rb
amq-client-0.7.0.alpha30 lib/amq/client/logging.rb
amq-client-0.7.0.alpha29 lib/amq/client/logging.rb
amq-client-0.7.0.alpha28 lib/amq/client/logging.rb