Sha256: 08cbc8129f5cd0bc5e86d21bf7bce9c97c18d278fdcfd0dea7e574ff8af0e1d2

Contents?: true

Size: 1.33 KB

Versions: 4

Compression:

Stored size: 1.33 KB

Contents

if RUBY_PLATFORM =~ /java/
  require 'java'
  require 'loggr/slf4j/jars'  
  Loggr::SLF4J::Jars.require_slf4j_jars!
  
  class ArrayAppender
    include Java::ChQosLogbackCore::Appender
    
    attr_reader   :events
    attr_accessor :name
    
    def initialize(name = 'ArrayAppender')
      @mutex = Mutex.new      
      @name = name
      @events = []
    end
    
    alias_method :setName, :name=
    alias_method :getName, :name
    
    def doAppend(event)
      @mutex.synchronize { @events.push(event) }
    end
    
    def stop
    end
    
    def last
      @events.last
    end
  end
end

class MiniTest::Unit::TestCase
  # Configures logback for testing et al.
  def setup_logback!
    if RUBY_PLATFORM =~ /java/
      @appender = ArrayAppender.new
      
      Java::OrgSlf4j::MDC.clear()
      logger_context = Java::OrgSlf4j::LoggerFactory.getILoggerFactory()
      root_logger = logger_context.getLogger(Java::OrgSlf4j::Logger::ROOT_LOGGER_NAME)
      root_logger.detachAndStopAllAppenders()
      root_logger.addAppender(@appender)
      root_logger.setLevel(Java::ChQosLogbackClassic::Level::ALL)
    end
  end
  
  # Verifies log event based on level & message
  def assert_log_event(exp_level, exp_message, event)
    assert_equal exp_level, event.getLevel().toInt()
    assert_equal exp_message, event.getFormattedMessage()
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
loggr-1.1.2 test/logback_helper.rb
loggr-1.1.1 test/logback_helper.rb
loggr-1.1.0 test/logback_helper.rb
loggr-1.0.0 test/logback_helper.rb