12 Replies Latest reply on Mar 18, 2015 5:52 PM by gerry.matte

    slf4j / logback

    ssamayoagt

      For more than a decade I used log4j but in my last JEE6 application (deployed in GF 3.x) I switched to slf4j & logback.

       

      Now I just started a new JEE application in WF8 and the first thing I did was to put slf4j & logback jars (logback-classic-x, logback-code-x & slf4j-api-x) in WEB-INF/lib and create logback.xml in source dir.

       

      But, even if I set debug="true" in logback.xml logging is not working.

       

      Someone using slf4j / logback with WF?

       

      Regards.

        • 1. Re: slf4j / logback
          ssamayoagt

          After surfing the web for +/-45 min I found this:

           

          http://tinyapps.blogspot.com/2013/01/getting-logback-and-slf4j-to-work-in.html

           

          Is little frustrating bumping with this problems!

           

          WF (and his ancestors) looks good but is harder to use compared with GF and other commercial ones.

           

          Regards.

          • 2. Re: slf4j / logback
            jamezp

            If you're using WildFly 8.0.0.Final you'll need to do one of two things*.

             

            Option 1 is to change the add-logging-api-dependencies attribute on the logging subsystem to false. This will stop the implicit logging dependencies from being added to all your deployments when being deployed.

             

            CLI Example:

            /subsystem=logging:write-attribute(name=add-logging-api-dependencies,value=false)
            

             

             

            Option 2 is to add a jboss-deployment-structure.xml to exclude the logging subsystem from your deployment. Have a look at the class loading documentation for more information on this.

             

            Example jboss-deployment-structure.xml

            <jboss-deployment-structure>
              <deployment>
                 <!-- exclude-subsystem prevents a subsystems deployment unit processors running on a deployment -->
                 <!-- which gives basically the same effect as removing the subsystem, but it only affects single deployment -->
                 <exclude-subsystems>
                    <subsystem name="logging" />
                </exclude-subsystems>
            </jboss-deployment-structure>
            

             

            * These steps are not documented yet, but will be very soon.

            --

            James R. Perkins

            • 3. Re: slf4j / logback
              gerry.matte

              I have been trying option 2 (using a jboss-deployment-structure.xml) with Wildfly 8.2.0.Final but have been unable to make slf4j+logback work.

              The subsystem exclusion for "logging" seems to not be working ... in my WEB-INF/lib I see the correct versions of logback and slf4j jars but I also see jboss-logging-3.1.4.GA.jar

               

              Logging calls embedded in my webapp are only written to the system console log .....

               

              I also tried excluding modules as recommended at http://tinyapps.blogspot.ca/2013/01/getting-logback-and-slf4j-to-work-in.html but there was still no logging output

               

              Is there a problem using the above recommendation with the current production version of Wildfly 8 ?

              • 4. Re: slf4j / logback
                jamezp

                Where are you putting your jboss-deployment-structure.xml?

                 

                --

                James R. Perkins

                • 5. Re: slf4j / logback
                  gerry.matte

                  Thanks for responding James.

                  In my Eclipse Luna maven project, both jboss-deployment-structure.xml and logback.xml are located in src/main/resources

                  When I generate the webapp using maven, they both end up in target/{project}/WEB-INF/classes and of course in the same location in the war file that I deploy to wildfly

                   

                  I took a look at the implicit module dependencies at the URL you identified and I noted that the logging subsystem is in the "Always Added" column and it's also in the conditional column if a beans.xml is present in the webapp.  In my case, the beans.xml is present ...... might that cause the logging system to be deployed even though my jboss-deployment-structure excludes logging ?

                  • 6. Re: slf4j / logback
                    gerry.matte

                    I managed to make logback work by using your option 1 (adding add-logging-api-dependencies value="false" to the logging subsystem using cli).

                     

                    Using a jboss-deployment-structure to exclude the logging subsystem does not seem to work with standalone-full.xml file and Wildfly 8.2.0.Final.

                     

                    I will file a JIRA so that someone else can investigate and determine if this is bug that needs to be fixed.

                    • 7. Re: slf4j / logback
                      jameslivingston

                      In my Eclipse Luna maven project, both jboss-deployment-structure.xml and logback.xml are located in src/main/resources

                      When I generate the webapp using maven, they both end up in target/{project}/WEB-INF/classes and of course in the same location in the war file that I deploy to wildfly

                      jboss-deployment-structure.xml should be in WEB-INF (or META-INF if it's not a WAR), not WEB-INF/classes, the same as web.xml. In a maven project, this means putting it in src/main/webapp rather than src/main/resources.

                      • 8. Re: slf4j / logback
                        gerry.matte

                        Thanks for the correction James Livingston. 

                         

                        However, after moving jboss-deployment-structure.xml from WEB-INF/classes up to WEB-INF, and removing the tag add-logging-api-dependencies tag from standalone-full.xml, I confirmed that the problem still occurs. 

                         

                        Although the server.log indicates that logback is being loaded with my webapp, my webapp logging is not processed by logback.  My application logging is handled by the logging subsystem instead of logback.

                         

                        I was required to re-insert the tag add-logging-api-dependencies tag into the logging subsystem in standalone-full.xml.

                        • 9. Re: slf4j / logback
                          jamezp

                          Are you deploying this app to a server running outside eclipse or is this being deployed to a server started by eclipse?

                           

                          --

                          James R. Perkins

                          • 10. Re: slf4j / logback
                            gerry.matte

                            I've been deploying it only within eclipse.

                            I've usually started the server from within eclipse since it's convenient for the code/test/modify/retest cycle.

                             

                            So, to test Wildfly startup without eclipse, I removed the add-logging-api-dependencies value="false" tag from my standalone-full.xml and started Wildfly from a windows command line.

                            Unexpectedly (to me) logback worked as it should - apparently the system default logging did NOT interfere with logback.

                             

                            So, I went back to eclipse, I did a Maven clean and Verify, ran clean with the server within eclipse, and started the server within eclipse.  Unexpectedly (again) logback worked as it should - apparently the system default logging did NOT interfere with logback.  Earlier this morning (see above) the webapp was failing to use logback without add-logging-api-dependencies value="false" in my standalone-full.xml.

                             

                            I've been making changes all morning .... it looks like I fixed something that was broken in my webapp.  If that is truly the case, I am embarrassed to have wasted your time.

                             

                            Were you able to replicate the problem ?

                            • 11. Re: slf4j / logback
                              jamezp

                              Ah it's not a problem at all. To be honest I haven't even tried it yet I wanted to make sure I replicated the environment first.

                               

                              IIRC eclipse incremental builds are a bit odd with maven at times. It's possible you moved things around, but it didn't make it into the deployed archive. I'm pretty sure I've seen this before and only a full clean and rebuild seems to work.

                               

                              --

                              James R. Perkins

                              • 12. Re: slf4j / logback
                                gerry.matte

                                Well .....  I rebuilt and redployed from scratch using eclipse.  I can no longer run my webapp with logback not working.

                                The only substantial change I recall making this morning was creating a custom filter to implement MDC loading in the slf4j logger.

                                 

                                I guess we conclude this is not a real problem.
                                Thanks for your efforts James (both of you).

                                Gerry