-
1. Re: JBoss 7.1.1.Final - Log4j - EAR File application - Logging not working
sanssan Jan 22, 2013 5:38 AM (in response to sanssan)Hi,
I have fixed this in 2 ways...
Case #1:
log4j.xml
<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE log4j:configuration SYSTEM "log4j.dtd"> <log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/"> <appender name="LDAP" class="org.apache.log4j.DailyRollingFileAppender"> <errorHandler class="org.jboss.logging.util.OnlyOnceErrorHandler"/> <param name="Append" value="true"/> <param name="File" value="${jboss.server.log.dir}/ldap.log"/> <layout class="org.apache.log4j.PatternLayout"> <param name="ConversionPattern" value="%d{dd.MM.yyyy HH:mm:ss.SSS} [%C{1}] - %m%n"/> </layout> </appender> <category name="com.xyz" additivity="false"> <priority value="DEBUG"/> <appender-ref ref="LDAP"/> </category> </log4j:configuration>
Add this a blank jar file and included inside EAR/lib. It worked like good.
Case #2:
Create a module in JBoss as modules and include the module in you application...
com |------- xyz |------- log4j |------- myapp |------- main |------- module.xml |------- log4j.xml
module.xml
<?xml version="1.0" encoding="UTF-8"?> <module xmlns="urn:jboss:module:1.1" name="com.xyz.log4j.myapp"> <resources> <resource-root path=""/> </resources> <dependencies> <module name="org.apache.log4j"/> </dependencies> </module>
And in your EAR/WAR, include your log4j custom module dependency... like below....
<jboss-deployment-structure> <deployment> <dependencies> <module name="com.xyz.log4j.myapp" /> </dependencies> <!-- Exclusions allow you to prevent the server from automatically adding some dependencies --> <exclusions> <module name="org.apache.log4j"/> <module name="org.slf4j" /> <module name="org.apache.commons.logging"/> <module name="org.log4j"/> <module name="org.jboss.logging"/> </exclusions> </deployment> <sub-deployment name="myapp.jar"> <dependencies> <module name="com.xyz.log4j.myapp" /> </dependencies> <exclusions> <module name="org.apache.log4j"/> <module name="org.slf4j" /> <module name="org.apache.commons.logging"/> <module name="org.log4j"/> <module name="org.jboss.logging"/> </exclusions> </sub-deployment> <sub-deployment name="myapp.war"> <dependencies> <module name="com.xyz.log4j.myapp" /> </dependencies> <exclusions> <module name="org.apache.log4j"/> <module name="org.slf4j" /> <module name="org.apache.commons.logging"/> <module name="org.log4j"/> <module name="org.jboss.logging"/> </exclusions> </sub-deployment> <sub-deployment name="myappPortal.war"> <dependencies> <module name="com.xyz.log4j.myapp" /> </dependencies> <exclusions> <module name="org.apache.log4j"/> <module name="org.slf4j" /> <module name="org.apache.commons.logging"/> <module name="org.log4j"/> <module name="org.jboss.logging"/> </exclusions> </sub-deployment> </jboss-deployment-structure>
Both worked excellent and In case 2, you can change logging level without touching application deployment.
If you want separate log files for each jar and war, still you create one more logging module and add dependency on the deployment structure xml.
Good luck buddies...
-
2. Re: JBoss 7.1.1.Final - Log4j - EAR File application - Logging not working
piyush.mnnit Apr 3, 2013 6:29 AM (in response to sanssan)For case2, can we moddify logging settings at runtime?
-
3. Re: JBoss 7.1.1.Final - Log4j - EAR File application - Logging not working
sanssan May 17, 2013 9:22 AM (in response to piyush.mnnit)Jain,
Sorry for the late reply.
You may not need to restart JBoss. But, you may need to redeploy the application.
I hope, this helps.
-
4. Re: JBoss 7.1.1.Final - Log4j - EAR File application - Logging not working
mwigglesworth-redhat May 26, 2013 12:54 PM (in response to sanssan)Greetings all.
I have been trying to figure out why this setup may not work, such that I am in a situation where this setup does not work in case 2.
The dependency in the module is not pulling in the org.apche.log4j at all, and we end up having to insert log4j.jar into the local classpath for this setup to work.
Can you provide some further input?
Simply put, your setup does not work in case 2 for me,unless I insert log4j.jar into the local classpath, under 7.1.3.
This is referenced on an old 2004 "JBoss Process Build" document, however, nothing really says you should have to put the jar into the local classpath for this setup to work. (At least that I have seen, or been able to locate online.)
Everyone just says, "include xyz.xml in your module, and put xyz module into your jboss-deployment-structure.xml and it just works," however the setup does not work unless you put the jar into the local classpath, which seems counter intutative to how a module should work. (New to module setup for this type of thing, also.)