12

I want to use the log4j2 JUL adapter in an OSGi environment. So I directly used log4j2 OSGi bundles and set the following system property in one of my custom OSGi bundle as mentioned here:

System.setProperty("java.util.logging.manager", "org.apache.logging.log4j.jul.LogManager");

It seems like this system property is not setting because logs coming from Java util framework is not going to appenders.

The OSGi framework that I'm using is Eclipse Equinox.

Where could I set this system property to work with OSGi?

EDIT:

As far as I understood here the problem is at the very begging of the JVM start the required property i.e. java.util.logging.manager is set to its default value, so setting this inside the OSGi environment is not effective, even we cannot set this property using -D option because the log4j2 OSGi bundles are not exposed to the class path, so that class not found exception occurs.

Any help is highly appreciate on this matter.

Grant
  • 4,413
  • 18
  • 56
  • 82

1 Answers1

3

Generally, if setting a property through the System.setProperty API does not work OK (maybe because the property has already been read before you can even overwrite it), you should try setting it from the very JVM start, entering "-D" arguments at the command line:

-Djava.util.logging.manager=org.apache.logging.log4j.jul.LogManager
Little Santi
  • 8,563
  • 2
  • 18
  • 46
  • 1
    This does not work, because to set this property the log4j2 jars needs to be in the class path, but the log4j classes in the OSGi environment is not visible to the main java class path. So if we try to set this property like that we will get class not found exception. – Grant Jul 17 '15 at 03:14
  • @Grant take a look at http://stackoverflow.com/a/43876384/3245762 to solve the classpath problem. – hbelmiro May 09 '17 at 17:37