4 Replies Latest reply on Jun 25, 2012 12:21 PM by elangovans

    How to exclude slf4j module in a war artifact?

    elangovans

      Hi all, we have recently started to using Jboss 7.1.1. After we moved to Jboss 7.1.1 our logging stopped working. We use slf4j with log4j impl. and our application logging is goes to a seperate log file.

       

      After some research I found that we need to exclude the slf4j module in jboss-deployment-structure.xml.

       

      First of all, Please let me know if I need to use jboss-deployment-structure.xml for this problem.

      Secondly, if I should use jboss-deployment-structure.xml, please show me some sample files, where should this file present in the war file, etc?

       

      Thanks

      Elangovan S

        • 1. Re: How to exclude slf4j module in a war artifact?
          jaysensharma

          Hi,

           

          Only For WAR's

          ==============

              If you want to use your own version of slf4j jar then you can exclude the JBoss provided slf4j using "WEB-INF/jboss-deployment-structure.xml"  and then place your own "slf4j.jar" inside "WEB-INF/lib" file as following:

           

          <?xml version="1.0" encoding="UTF-8"?>

          <jboss-deployment-structure>

             <deployment>

                  <exclusions>

                        <module name="org.slf4j" />

                  </exclusions>

             </deployment>

          </jboss-deployment-structure>

           

           

          For EAR's (We need to exclude the slf4j module at Each Sub-Module level as following) using "YOUR_EAR/META-INF/jboss-deployment-structure.xml"

          ===========================================================

           

          <?xml version="1.0" encoding="UTF-8"?>

          <jboss-deployment-structure>

                <deployment>

                     <exclusions>

                         <module name="org.slf4j" />

                    </exclusions>

                </deployment>

           

                <sub-deployment name="YOUR_WEBAPP.war">

                     <exclusions>

                         <module name="org.slf4j" />

                     </exclusions>

               </sub-deployment>

          </jboss-deployment-structure>

          • 2. Re: How to exclude slf4j module in a war artifact?
            elangovans

            Thanks for the speedy response, Jay Kumar.

             

            I think I am still doing something wrong. My settings are not getting effective. I am attaching a link to mytest file (https://dl.dropbox.com/sh/4aqxcs27jp4w6pi/c0SoVQSFGv/loghub-test-app-1.0.0.0-SNAPSHOT.war?dl=1. Based on my log4j.xml configuration I expect a log file called loghub.log under jboss log folder. That's not happening. Please point out what I am doing wrong.

             

            thanks.

             

            To test drop the file into deployment folder and http://localhost:8080/loghubtest/lhtest

            • 3. Re: How to exclude slf4j module in a war artifact?
              jaysensharma

              Hi,

               

                          I edited a couple of things in your Project and it started working at my end:

               

              Change-1).  Altered the "WEB-INF/classes/log4j.xml" file  Just to generate the logs in JBoss Log directory:

               

              <?xml version="1.0" encoding="UTF-8" ?>

              <!DOCTYPE log4j:configuration SYSTEM "log4j.dtd">

              <log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/">

                    <appender name="R" class="org.apache.log4j.RollingFileAppender">

                                  <param name="file" value="${jboss.server.log.dir}/sampleslf4j.log" />

                                  <param name="MaxFileSize" value="100KB" />

                                  <param name="MaxBackupIndex" value="10" />

                                  <layout class="org.apache.log4j.PatternLayout">

                                  <param name="ConversionPattern" value="[%r,%c{1},%t] %m%n"/>

                              </layout>

                        </appender>

               

                        <category name="org.weld">

                           <priority value="DEBUG" />

                           <appender-ref ref="R" />

                        </category>

               

                         <root>

                           <priority value="debug" />

                           <appender-ref ref="R" />

                        </root>

              </log4j:configuration>

               

              Change-2).  Most important change .. I added "WEB-INF/jboss-deployment-structure.xml" file in oyur WAR as following:

               

              <?xml version="1.0" encoding="UTF-8"?>

              <jboss-deployment-structure>

                 <deployment>

                      <exclusions>

                            <module name="org.slf4j" />

                            <module name="org.apache.log4j" />

                        </exclusions>

                 </deployment>

              </jboss-deployment-structure>

               

              After deploying the application as soon as i hit the URL:   http://localhost:8080/sampleslf4j/rest/test      I was able to see a log file generated inside "jboss-as-7.1.1.Final/standalone/log/sampleslf4j.log"  with relevant data.

               

              ATTACHING Modified WAR File.

              • 4. Re: How to exclude slf4j module in a war artifact?
                elangovans

                Thanks Jay Kumar, Followed your instructions... This worked for me! Appreciate your help.