Search code examples
log4j2websphere-libertyopen-liberty

Websphere Liberty: How to specify log4j2 configuration location?


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?


Solution

  • 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>