#encoding: utf-8
require 'singleton'
require 'java'
java_import org.slf4j.Logger;
java_import org.slf4j.LoggerFactory;
java_import 'ch.qos.logback.classic.LoggerContext';
java_import 'ch.qos.logback.core.Context';
java_import 'ch.qos.logback.core.util.StatusPrinter';
class Wisper
include Singleton
include Java::ChQosLogbackCore.Context
#include Java::ChQosLogbackClassic.LoggerContext
def test0(name)
lc = LoggerFactory.getILoggerFactory
StatusPrinter.print(lc)
# ↑ this call return
# org.jruby.exceptions.RaiseException: (NameError) no method 'print' for arguments (org.slf4j.impl.Slf4jLoggerFactory) on Java::ChQosLogbackCoreUtil::StatusPrinter
end
def test1(name)
lc = LoggerFactory.getILoggerFactory
stprint = StatusPrinter.java_method :print, [Context.java_class]
stprint.call(lc)
# ↑ this call return
# org.jruby.exceptions.RaiseException: (TypeError) failed to coerce org.slf4j.impl.Slf4jLoggerFactory to ch.qos.logback.core.Context
end
def test2(name)
lc = LoggerFactory.getILoggerFactory.to_java(LoggerContext.java_class)
# ↑ this call return
# org.jruby.exceptions.RaiseException: (TypeError) unable to convert to type: ch.qos.logback.classic.LoggerContext
stprint = StatusPrinter.java_method :print, [Context.java_class]
stprint.call(lc)
end
def test3(name)
lc = LoggerFactory.getILoggerFactory
stprint = StatusPrinter.java_method :print, [Context.java_class]
stprint.call(lc.java_object)
# ↑ this call return
# org.jruby.exceptions.RaiseException: (NoMethodError) undefined method `getStatusManager' for #<Java::JavaObject:0x7cfecfcb>`
end
end
Wisper.instance.test3('mylogger')