Trying to deploy a liberty application to OCP and merge the liberty logging with the application logging per example: https://openliberty.io/blog/2020/05/19/log4j-openshift-container-platform.html
Our application uses LOG4J2 to configure and run the logging. This worked sofar with following dependencies.
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-core</artifactId>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-slf4j-impl</artifactId>
</dependency>
and use the following line of code to tell the app where the log4J2.xml file is located
Configurator.initialize(null, log4jConfigUrlFile);
our logging ended up in the logfiles and everything was fine. However now we need some way to use Log4J2 to configure our loggers but the logging itself must end up in JUL so it can be used by OCP and their EFK stack.
I have been trying with the following dependencies.
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-to-slf4j</artifactId>
<version>2.13.0</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-jdk14</artifactId>
<version>1.7.7</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>1.7.25</version>
</dependency>
There are no compile issues and the program starts and I see logging appear in the console. However when I try tweaking our log4j2.xml (who is on the classpath) and for example don't want to see the info messages they still appear. it seems it's not loaded or not used. Another thing that I notice is that the LoggingFactory is the one from slf4j-jdk14 maybe that is an issue. We also can't use the Configurator anymore since that is part of log4j-core and you can't have two implementations (log4j-to-slf4j) on the same classpath.
I also tried setting the logfile location property
-Dlog4j.configurationFile=./resources/log4j/log4j2.xml
I tried this with several permutations of directory structure just to be sure and isn't working. Also tried the following.
-Dorg.apache.logging.log4j.simplelog.StatusLogger.level=TRACE
Just to get some more debug output but haven't gotten that even to work. Is there any other thing I can try ?
My concrete endgoal is
- Configure logging by means of log4j2.xml
- Have logging end up as java.util.logging in the console