Вопрос

I have a JRuby project that requires a Java jar. The Java jar is instrumented for logging using log4j. I don't need to use log4j in my JRuby code, but I want to run the JRuby code so that when the instrumented Java classes are called they respect the log4j settings I've specified.

I'm using Trinidad and had hoped that just passing in the 'normal' log4j JVM arguments would do the trick. Here's the process information when I just run Trinidad:

/Library/Java/JavaVirtualMachines/jdk1.8.0.jdk/Contents/Home/bin/java -Xmx500m -Xss2048k  -Djffi.boot.library.path=/Users/eebbesen/.rvm/rubies/jruby-1.7.5/lib/jni -Dfile.encoding=UTF-8 -Djava.net.preferIPv4Stack=true -Xbootclasspath/a:/Users/eebbesen/.rvm/rubies/jruby-1.7.5/lib/jruby.jar -classpath : -Djruby.home=/Users/eebbesen/.rvm/rubies/jruby-1.7.5 -Djruby.lib=/Users/eebbesen/.rvm/rubies/jruby-1.7.5/lib -Djruby.script=jruby -Djruby.shell=/bin/sh org.jruby.Main script/trinidad

and here's what I tried to get log4j working:

/Library/Java/JavaVirtualMachines/jdk1.8.0.jdk/Contents/Home/bin/java -Xmx500m -Xss2048k -Djffi.boot.library.path=/Users/eebbesen/.rvm/rubies/jruby-1.7.5/lib/jni -Dfile.encoding=UTF-8 -Djava.net.preferIPv4Stack=true -Xbootclasspath/a:/Users/eebbesen/.rvm/rubies/jruby-1.7.5/lib/jruby.jar -classpath : -Djruby.home=/Users/eebbesen/.rvm/rubies/jruby-1.7.5 -Djruby.lib=/Users/eebbesen/.rvm/rubies/jruby-1.7.5/lib -Djruby.script=jruby -Dlog4j.debug=true -Dlog4j.configuration=file:log4j.properties -Djruby.shell=/bin/sh org.jruby.Main script/trinidad

so I'm just adding

-Dlog4j.debug=true -Dlog4j.configuration=file:log4j.properties

to what Trinidad is already doing.

What I'm not seeing is any of the log4j logging happening when I run Trinidad. However, when I use Rails console my logging statements are appearing.

The posts I've seen cover how to use log4j from within JRuby, but I would like to accomplish this via JVM arguments if possible.

Это было полезно?

Решение

I got this to work by setting JVM options JRuby-style:

export JRUBY_OPTS="-J-Dlog4j.debug=true -J-Dlog4j.configuration=file:/absolute/path/to/log4j.properties"
trinidad

This overwrote log4j.properties specified in my Java jar and I was able to manipulate log levels of Java classes in (and called by classes explicitly in) the jar file.

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top