Logging with slf4j in 7.1.0.Final
norad_2 Feb 22, 2012 7:58 PMHi All,
In 7.1.0.CR1b I could include my own slf4j-api/slf4j12 and log4j.xml and have my application not use the JBoss logging modules.
I did this for the following reasons:
1. JBoss logging seems to be based on java.util.logging, which has no support for Message Diagnostic Context, which I use heavily
2. JBoss logging currently has no support for JMS Appenders like org.apache.log4j.net.JMSAppender
Based on what I see in this JIRA, and what I am seeing since I upgraded from CR1b to Final, it seems like JBoss logging has been forced onto us.
https://issues.jboss.org/browse/AS7-1389
"Log API dependencies should be included automatically in deployments"
The JIRA mentions being able to exclude the logging dependencies if I want to bring in my own.
I created a jboss-deployment-structure file
{code:xml}
<jboss-deployment-structure>
<ear-subdeployments-isolated>false</ear-subdeployments-isolated>
<deployment>
<exclusions>
<module name="org.slf4j"/>
<module name="org.apache.commons.logging"/>
<module name="org.log4j"/>
</exclusions>
</deployment>
</jboss-deployment-structure>
{code}
Now when I try to startup JBoss, I get warnings and errors and JBoss does not startup
{code}
00:30:07,297 WARN [org.jboss.modules] [MSC service thread 1-3] Failed to define class org.slf4j.Logger in Module "deployment.project.ear:main" from Service Module Loader: java.lang.LinkageError: loader constraint violation: loader (instance of org/jboss/modules/ModuleClassLoader) previously initiated loading for a different type with name "org/slf4j/Logger"
{code}
{code}
00:30:07,308 ERROR [org.jboss.msc.service.fail] [MSC service thread 1-3] MSC00001: Failed to start service jboss.deployment.subunit."project.ear"."project-services.jar".POST_MODULE: org.jboss.msc.service.StartException in service jboss.deployment.subunit."project.ear"."project-services.jar".POST_MODULE: Failed to process phase POST_MODULE of subdeployment "project-services.jar" of deployment "project.ear"
at org.jboss.as.server.deployment.DeploymentUnitPhaseService.start(DeploymentUnitPhaseService.java:119) [jboss-as-server-7.1.0.Final.jar:7.1.0.Final]
at org.jboss.msc.service.ServiceControllerImpl$StartTask.startService(ServiceControllerImpl.java:1811) [jboss-msc-1.0.2.GA.jar:1.0.2.GA]
at org.jboss.msc.service.ServiceControllerImpl$StartTask.run(ServiceControllerImpl.java:1746) [jboss-msc-1.0.2.GA.jar:1.0.2.GA]
at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886) [rt.jar:1.6.0_29]
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908) [rt.jar:1.6.0_29]
at java.lang.Thread.run(Thread.java:662) [rt.jar:1.6.0_29]
Caused by: java.lang.RuntimeException: Error getting reflective information for class com.example.project.package.api.remote.AbstractServiceLocator with ClassLoader ModuleClassLoader for Module "deployment.project.ear:main" from Service Module Loader
at org.jboss.as.server.deployment.reflect.DeploymentReflectionIndex.getClassIndex(DeploymentReflectionIndex.java:70) [jboss-as-server-7.1.0.Final.jar:7.1.0.Final]
at org.jboss.as.ee.metadata.MethodAnnotationAggregator.runtimeAnnotationInformation(MethodAnnotationAggregator.java:58)
at org.jboss.as.ee.component.deployers.InterceptorAnnotationProcessor.handleAnnotations(InterceptorAnnotationProcessor.java:70)
at org.jboss.as.ee.component.deployers.InterceptorAnnotationProcessor.processComponentConfig(InterceptorAnnotationProcessor.java:117)
at org.jboss.as.ee.component.deployers.InterceptorAnnotationProcessor.deploy(InterceptorAnnotationProcessor.java:54)
at org.jboss.as.server.deployment.DeploymentUnitPhaseService.start(DeploymentUnitPhaseService.java:113) [jboss-as-server-7.1.0.Final.jar:7.1.0.Final]
... 5 more
Caused by: java.lang.NoClassDefFoundError: org/slf4j/Logger
at java.lang.Class.getDeclaredMethods0(Native Method) [rt.jar:1.6.0_29]
at java.lang.Class.privateGetDeclaredMethods(Class.java:2427) [rt.jar:1.6.0_29]
at java.lang.Class.getDeclaredMethods(Class.java:1791) [rt.jar:1.6.0_29]
at org.jboss.as.server.deployment.reflect.ClassReflectionIndex.<init>(ClassReflectionIndex.java:65) [jboss-as-server-7.1.0.Final.jar:7.1.0.Final]
at org.jboss.as.server.deployment.reflect.DeploymentReflectionIndex.getClassIndex(DeploymentReflectionIndex.java:66) [jboss-as-server-7.1.0.Final.jar:7.1.0.Final]
... 10 more
Caused by: java.lang.ClassNotFoundException: org.slf4j.Logger from [Module "deployment.project.ear:main" from Service Module Loader]
at org.jboss.modules.ModuleClassLoader.findClass(ModuleClassLoader.java:190)
at org.jboss.modules.ConcurrentClassLoader.performLoadClassUnchecked(ConcurrentClassLoader.java:468)
at org.jboss.modules.ConcurrentClassLoader.performLoadClassChecked(ConcurrentClassLoader.java:456)
at org.jboss.modules.ConcurrentClassLoader.performLoadClassChecked(ConcurrentClassLoader.java:423)
at org.jboss.modules.ConcurrentClassLoader.performLoadClass(ConcurrentClassLoader.java:398)
at org.jboss.modules.ConcurrentClassLoader.loadClass(ConcurrentClassLoader.java:120)
... 15 more
{code}
I have the necessary slf4j jars included in my ear, and this is all working fine in CR1b.