Sha256: 5907f9bcec72e3de8f55ea155bbac9e8d549c39833067f965938a2ab6d045fc6

Contents?: true

Size: 910 Bytes

Versions: 6

Compression:

Stored size: 910 Bytes

Contents

require 'java'
module Slf4r
  class LoggerFacade

    protected

    def format(exception)
      (": #{exception.message}:\n\t#{exception.backtrace.join("\n\t") if exception.backtrace }") if exception
    end

    public

    attr_reader :name

    attr_reader :logger

    def initialize(name)
      @name = name
      @logger = org.slf4j.LoggerFactory.getLogger(name.to_s.sub(/^::/, '').gsub(/::/, '.'))
    end

    [:debug, :info, :warn, :error, :fatal].each do |level|
      class_eval <<-CODE
    def #{level}?
      @logger.is_#{level}_enabled
    end

    def #{level}(msg = nil, exception = nil)
      if(@logger.is_#{level}_enabled)
        msg, exception = yield if block_given?
        if(exception.type == NativeException)
          @logger.#{level}(msg, exception.cause)
        else
          @logger.#{level}("\#{msg}\#{format(exception)}")
        end
      end
    end
CODE
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
slf4r-0.4.2 lib/slf4r/java_logger.rb
slf4r-0.4.1 lib/slf4r/java_logger.rb
slf4r-0.4.0 lib/slf4r/java_logger.rb
slf4r-0.3.3 lib/slf4r/java_logger.rb
slf4r-0.3.2 lib/slf4r/java_logger.rb
slf4r-0.3.1 lib/slf4r/java_logger.rb