Websphere Liberty: How to specify log4j2 configuration location?

不羁的心 提交于 2020-01-24 17:27:25

问题


I'm trying to tell Websphere Liberty where is located my log4j2.xmlfile, but it isn't working.

In my file jvm.options I configure:

-Dlog4j.configurationFile=file:///${server.config.dir}/log4j2.xml

but it looks like Liberty does not understand the variable ${server.config.dir} in the jvm.options file. The file is in the same directory of the server.xml file.

How would I specify the log4j2.xml location for Liberty?


回答1:


I think it should be possible by creating a Library entry in your server.xml such as:

<library id="log4jLib">
   <folder dir="/opt/log4j2/config"/>
</library>

where the directory specified contains the log4j2 properties or xml file.

Then specify a classloader for your application like this:

<application id="test" name="test" type="ear" location="test.ear">
  <classloader commonLibraryRef="log4jLib" />
</application>



回答2:


The ${server.config.dir} variable is one of the Liberty built-in server config variables, these only apply within the server.xml (and included configurations).

When you run a Liberty server, the user.dir gets set to the same thing as ${server.config.dir}, so you could just specify the relative path to your log4j2.xml file in jvm.options as:

-Dlog4j.configurationFile=log4j2.xml



回答3:


There are a few ways of configuring log4j in WebSphere. Aside from the library entries method mentioned by pseudonym, you can simply drop the log4j2 configuration file to the global library directory at

wlp/usr/servers//lib/global

If there are files present in above location at the time an application is started, and that application does not have a classloader element configured, the application uses these libraries. If a class loader configuration is present, these libraries are not used unless the global library is explicitly referenced.

You can find more details about the global libraries in this link

WebSphere Liberty Shared Libraries



来源:https://stackoverflow.com/questions/55858059/websphere-liberty-how-to-specify-log4j2-configuration-location

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!