如何在OSGi环境中为log4j2 JUL适配器设置系统属性

时间:2023-01-18 12:24:01

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:

我想在OSGi环境中使用log4j2 JUL适配器。因此,我直接使用log4j2 OSGi包,并在其中一个自定义OSGi包中设置了以下系统属性:

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.

看起来这个系统属性没有设置,因为来自Java util框架的日志不会添加到appender中。

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

我使用的OSGi框架是Eclipse Equinox。

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

我可以将这个系统属性设置为使用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.

就我在这里所理解的,问题在于JVM启动所需的属性,即java.util.logging。manager被设置为其默认值,因此在OSGi环境中设置这个值是无效的,即使我们不能使用-D选项设置这个属性,因为log4j2 OSGi捆绑包没有公开到类路径中,因此类不会出现异常。

Any help is highly appreciate on this matter.

在这件事上任何帮助都是非常感谢的。

1 个解决方案

#1


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:

一般来说,如果通过系统设置属性。setProperty API不能正常工作(可能是因为该属性在重写之前已经被读取),您应该尝试从JVM start开始设置它,在命令行输入“-D”参数:

-Djava.util.logging.manager=org.apache.logging.log4j.jul.LogManager

#1


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:

一般来说,如果通过系统设置属性。setProperty API不能正常工作(可能是因为该属性在重写之前已经被读取),您应该尝试从JVM start开始设置它,在命令行输入“-D”参数:

-Djava.util.logging.manager=org.apache.logging.log4j.jul.LogManager