Reputation: 39183
I'm trying to tell Websphere Liberty where is located my log4j2.xml
file, 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?
Upvotes: 2
Views: 3495
Reputation: 1083
For Liberty I do the following; I have a jvm.options file containing:
-Dlog4j.configurationFile=log4j2.xml
I place both files (log4j2.xml and jvm.options) in the server config. I.e where tour server.xml etc is placed:
usr/servers/<myserver>:
server.xml
jvm.options
log4j2.xml
That does the trick for me.
Upvotes: 2
Reputation: 11
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
Upvotes: 1
Reputation: 42926
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
Upvotes: 2
Reputation: 1519
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>
Upvotes: 3