Red Hat Bugzilla – Bug 986864
Migration Guide for Logging in EAP 6.1 is incomplete
Last modified: 2014-09-29 14:36:22 EDT
Title: Update Application Code for Third-party Logging Frameworks
Describe the issue:
The steps described to configure logging in the application without using the logging subsystem are incomplete. There are several modules that have to be excluded as well to make it work. The log4j.xml (or log4j.properties) file is not found if it is simply included in the lib-Directory of the EAR.
Suggestions for improvement:
The complete exclusion list, that worked for me is:
<module name="org.apache.commons.logging" />
<module name="org.apache.log4j" />
<module name="org.jboss.logging" />
<module name="org.jboss.logging.jul-to-slf4j-stub" />
<module name="org.jboss.logmanager" />
<module name="org.jboss.logmanager.log4j" />
<module name="org.slf4j" />
<module name="org.slf4j.impl" />
In addition the modules have to be excluded for every sub-deplyoment (EJB-JARs or WARs), too.
The log4j configuration file has to be packaged in a JAR file so that it is found.
Adding James so he can assist in the details.
If you don't want to use the log4j dependency provided by the container, then you only need to exclude the org.apache.log4j module. The mother module exclusions are not required. It is true though that the modules would need to be excluded for each subdeployment.
The only reason you'd have to exclude slf4j, commons-logging or jboss-logmanager is if you used those libraries as well and you wanted to provide them. Otherwise there is no reason to exclude them.
As far as it being packaged in a JAR, that works but it's not required. It will work in the lib directory if you modify the jboss-deployment-structure.xml to include the following
<module name="org.apache.log4j" />
<resource-root path="lib" />
That only needs to be on the top-level deployment for an EAR. In a WAR putting the configuration file in the WEB-INF/classes works fine.
All this said in 6.2+ using a log4j properties file and letting the container configure your logging works quite well. There is no real reason to exclude it and use your own log4j unless you have some very specific needs.
With regards to some changes that should be noted in the docs for 6.3. There are two new attributes on the logging subsystem that help with excluding the 3rd party logging dependencies from being added to the deployments.
The two new attributes are add-logging-api-dependencies and use-deployment-logging-config.
The use-logging-api-dependencies controls whether or not the container adds implicit logging API dependencies to your deployments. If set to true, the default, all the implicit logging API dependencies are added. If set to false the dependencies are not added to your deployments.
The use-deployment-logging-config controls whether or not your deployment is scanned for per-deployment logging. If set to true, the default, per-deployment logging is enabled. Set to false to disable this feature.
Also the org.jboss.as.logging.per-deployment system property has been deprecated. It's advised to set use-deployment-logging-config to false instead.
The add-logging-api-dependencies also removes the need to include a jboss-deployment-structure.xml to exclude each dependency. Note though that the attribute is global so if only one deployment needs to exclude the logging dependencies a jboss-deployment-structure.xml is still required.
Another option is to use a jboss-deployment-structure.xml to exclude the logging subsystem all together. This would be akin to setting both attributes to false for the deployment.
There is some more information about the changes here https://docs.jboss.org/author/display/WFLY8/Logging+Configuration and https://docs.jboss.org/author/display/WFLY8/How+To#HowTo-HowdoIuselog4j.propertiesorlog4j.xmlinsteadofusingtheloggingsubsystemconfiguration%3F. That is for WildFly 8, but the two attributes were ported over to EAP 6.3.
This can be verified here:
Verified with EAP 6.3.0 ER2, revision 6.3.0-8