How do I get the equivalent of the following Java code (initializing a SLF4J logger) working in JRuby?
private final static Logger logger = LoggerFactory.getLogger(Manager.class);
Let’s say that my (working) example script looks like this:
def test(some_input)
logger = org.slf4j.LoggerFactory.getLogger("SCRIPT");
logger.error("Error...")
end
Because I’m a JRuby newbie I only got it working inside the method, and not with a .class in the getLogger.
So the questions are:
- How do I call
getLoggerusing a.classas an argument in the JRuby code? - How do I put the Logger object somewhere as a static ? I would like to avoid the
getLoggerevery time I call the method.
Thank you for your help!
you’ll need to use
java_classto get the “correct” class that is a (wrapped)java.lang.Classand not a ruby class as is withjava.util.Date.classe.g. :as for storing it “statically” you could use class variables, but keep in mind that they are shared across the inheritance hierarchy, example :