Sha256: 8b9e49c29cca6350503216c91e4f0f9830c1af965cc7bb028822a07341797822

Contents?: true

Size: 1.25 KB

Versions: 1

Compression:

Stored size: 1.25 KB

Contents

module HornetQ
  # Internal use only class for delegating HornetQ logging into the Rails or Ruby
  # loggers
  # 
  private

  # HornetQ requires a factory from which it can create a logger per thread and/or class 
  class LogDelegateFactory
    include 
    
    def createDelegate(klass)
      LogDelegate.new(klass.name)
    end
  end
  
  # Delegate HornetQ log calls to Rails, Ruby or custom logger
  class LogDelegate
    include Java::org.hornetq.spi.core.logging::LogDelegate
    
    # TODO: Carry class_name over into logging entries depending on implementation
    def initialize(class_name)
      @class_name = class_name
    end
    
    # DRY, generate a method for each required log level
    ['debug', 'error', 'fatal', 'info', 'trace', 'warn'].each do |level|
      eval <<-LOG_LEVEL_METHOD
      def #{level}(message)
        @logger.#{level}("[\#{@class_name}] \#{message}") if is#{level.capitalize}Enabled
      end

      def #{level}(message, t)
        if is#{level.capitalize}Enabled
          @logger.#{level}("[\#{@class_name}] \#{message}. \#{t.to_string}")
          @logger.#{level}(t.stack_trace.to_string)
        end
      end

      def is#{level.capitalize}Enabled
        @logger.#{level}?
      end
      LOG_LEVEL_METHOD
    end

  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
jruby-hornetq-0.2.5.alpha lib/hornetq/common/log_delegate.rb