I have a Keycloak EAR module, deployed on Keycloak 11.0. In my EAR module I want to use log4j2 logging library with slf4j. I successfully accomplished this by adding the following dependencies in the pom directly: log4j-slf4j-impl
, log4j-api
& log4j-core
.
Wildfly logging dependencies are excluded by setting add-logging-api-dependencies
to false
. log4j2.xml
is specified outside the packaged EAR and is referenced with log4j.configurationFile
system property.
Now the problem. I also want Keycloak to use log4j2 but I cannot get this to work. Keycloak is using Jboss Logging wrapper which always picks up JbossLogManager
no matter which logging provider I set - I always get either ClassNotFoundException
or NoClassDefFoundError
.
I realize there is a classpath problem but I am out of ideas at this point. I tried creating log4j-slf4j-impl
, log4j-api
& log4j-core
Wildfly modules with the following command but I still get the same error.
./jboss-cli.sh --command="module add --name=org.apache.logging.log4j.log4j-api --resources=/Users/jernej/log4j-api-2.13.3.jar"
If I understand correctly, log4j2 should be in the classpath on Wildfly startup (when searching for LoggerProvider
) and Jboss Logging findProvider
method should return Log4j2LoggerProvider
if modules are correctly added? How can I accomplished this?
Suppose I want to use log4j2 appender, located in separate library. If I add this library as a Wildfly module this log4j2 appender can then be used by other deployments as well - e.g. keycloak-server.war?