10 Replies Latest reply on Jul 26, 2012 12:39 PM by Patrick Ruckstuhl

    AS7 Logging - org.jboss.logging.jul-to-slf4j-stub ?

    rang s Newbie

      Any idea what this stub is about - org.jboss.logging.jul-to-slf4j-stub ?

       

      Any documentation link to know about the above and similar logging mechanisms would be appreciated.

       

      Thanks,

      Rang

        • 1. Re: AS7 Logging - org.jboss.logging.jul-to-slf4j-stub ?
          David Lloyd Master

          Some people package the JUL-to-SLF4J bridge artifact (provided by the SLF4J project) in their web apps.  This JAR screws up the container logging so we emulate it with a no-op stub, overriding the deployment's version, allowing their logging to work properly.

           

          Message was edited by: David Lloyd (fixed a typo)

          • 2. Re: AS7 Logging - org.jboss.logging.jul-to-slf4j-stub ?
            rang s Newbie

            Thanks David for the reply.

             

            1.) You mentioned that to avoid the JUL-to-SLF4J artificat of SLF4J, a no-op stub is added. How do I specify the underneath implementaion. For example- if I intend to use log4j, do I just need to package the log4j.jar and the config file in my jar file ?

             

            2.) Also. as per https://docs.jboss.org/author/display/AS7/Implicit+module+dependencies+for+deployments , org.jboss.logging.jul-to-slf4j-stub is a implicit module. This does not seem to be the case. I had to explicitly had a dependency to avoid ClassNotFound Errors in 7.1.2.FINAL.

            • 3. Re: AS7 Logging - org.jboss.logging.jul-to-slf4j-stub ?
              David Lloyd Master

              rang s wrote:

               

              Thanks David for the reply.

               

              1.) You mentioned that to avoid the JUL-to-SLF4J artificat of SLF4J, a no-op stub is added. How do I specify the underneath implementaion. For example- if I intend to use log4j, do I just need to package the log4j.jar and the config file in my jar file ?

              If you want your application to have separate logging, you only need to include your log4j.xml, log4j.properties, or logging.properties file and that's it.  Then your application's logging will be configured according to that file.  The logging is always treated the same regardless of whether you use slf4j, JUL, log4j, or commons-logging; this means you could use a log4j.xml and use the JUL API if you wanted to, and it'd work correctly.

               

              If you want your application to use container logging, just leave out any logging config file.

               

              Either way, any logging JARs you include in your deployment should be automatically ignored by the container unless you specifically override it using jboss-deployment-structure.xml, which you normally should not do.

               

              rang s wrote:

               

              2.) Also. as per https://docs.jboss.org/author/display/AS7/Implicit+module+dependencies+for+deployments , org.jboss.logging.jul-to-slf4j-stub is a implicit module. This does not seem to be the case. I had to explicitly had a dependency to avoid ClassNotFound Errors in 7.1.2.FINAL.

              OK, that sounds like a bug to me.  Could you please log an issue at https://issues.jboss.org/browse/AS7?  Thanks.

              • 4. Re: AS7 Logging - org.jboss.logging.jul-to-slf4j-stub ?
                rang s Newbie

                Looks like either something is missing or I am doing it wrongly.

                 

                This is the scenario I am trying. I have a EJB jar file. It uses java util logging. Now I wish to use JUL-to-SLF4J stub and then wish to log the messages via log4j. i.e I want the java.util.logging calls to direct to slf4j via SLF4JBridgeHandler( I have specified this handled in logging.properties bundled in ejb jar, hope this is the right way) .

                 

                I have tried adding log4j.properties in the ejb jar but the messages were not logged. For slf4j to log messages via log4j, do I need to do something more ?( SLF4J says that an application needs to have slf4j-log4j12-1.6.6.jar and log4j. The former I bundle with my ejb jar. The latter is provided by JBoss AS7. Hope this is fine)

                 

                Or to understand better, how can I direct by j.u.l to slf4j to JCL -> some logging implemenation

                 

                Regarding point 2 . I have created a issue - > https://issues.jboss.org/browse/AS7-5174

                 

                Message was edited by: rang s - Added the JCL part

                • 5. Re: AS7 Logging - org.jboss.logging.jul-to-slf4j-stub ?
                  David Lloyd Master

                  rang s wrote:

                   

                  Looks like either something is missing or I am doing it wrongly.

                   

                  This is the scenario I am trying. I have a EJB jar file. It uses java util logging. Now I wish to use JUL-to-SLF4J stub and then wish to log the messages via log4j.

                  There's your first issue.  You do not need to use JUL-to-SLF4J in order to log JUL messages in AS 7.  Our stub version of this library actually does nothing and is only there to prevent errors in existing code.

                   

                   

                  rang s wrote:

                   

                  ( I have specified this handled in logging.properties bundled in ejb jar, hope this is the right way) .

                   

                  I have tried adding log4j.properties in the ejb jar but the messages were not logged.

                  If you have both a logging.properties and a log4j.properties, I believe the log4j.properties will be ignored.  You can only have one logging configuration file per deployment, and that configuration applies to all logging APIs, including slf4j, JUL, log4j, etc.  AS automatically unifies all log frameworks.

                   

                  rang s wrote:

                   

                  ( SLF4J says that an application needs to have slf4j-log4j12-1.6.6.jar and log4j. The former I bundle with my ejb jar. The latter is provided by JBoss AS7. Hope this is fine)

                  You do not need any slf4j JARs as AS7 already provides them all.  Any slf4j JAR you do provide should be ignored, though I'd leave them out just to be safe.

                  • 6. Re: AS7 Logging - org.jboss.logging.jul-to-slf4j-stub ?
                    Patrick Ruckstuhl Newbie

                    rang s wrote:

                     

                    ( I have specified this handled in logging.properties bundled in ejb jar, hope this is the right way) .

                     

                    I have tried adding log4j.properties in the ejb jar but the messages were not logged.

                    If you have both a logging.properties and a log4j.properties, I believe the log4j.properties will be ignored.  You can only have one logging configuration file per deployment, and that configuration applies to all logging APIs, including slf4j, JUL, log4j, etc.  AS automatically unifies all log frameworks.

                     

                    This doesn't seem to work for me.

                     

                    If I create the file

                     

                    my.ear/META-INF/log4j.properties

                     

                    with

                     

                    log4j.rootLogger=DEBUG, FA

                     

                    log4j.appender.FA=org.apache.log4j.FileAppender

                    log4j.appender.FA.File=/tmp/my.log

                    log4j.appender.FA.layout=org.apache.log4j.PatternLayout

                    log4j.appender.FA.layout.ConversionPattern= %-4r [%t] %-5p %c %x - %m%n

                     

                     

                    this results in nothing in the server.log and an empty /tmp/my.log

                     

                     

                    but if I create a

                     

                    my.ear/META-INF/logging.properties

                     

                    this results in everything beeing logged to /tmp/my.log

                     

                     

                    We're using SLF4J in our application and also using a library that uses COMMONS-LOGGING

                    • 7. Re: AS7 Logging - org.jboss.logging.jul-to-slf4j-stub ?
                      Patrick Ruckstuhl Newbie

                      Forgot to add this, if log in my application directly using the l4j api, this (and only this) shows up in /tmp/my.log

                      • 8. Re: AS7 Logging - org.jboss.logging.jul-to-slf4j-stub ?
                        David Lloyd Master

                        Patrick Ruckstuhl wrote:

                         

                        If I create the file

                         

                        my.ear/META-INF/log4j.properties

                         

                        with [...] this results in nothing in the server.log and an empty /tmp/my.log

                         

                        but if I create a

                         

                        my.ear/META-INF/logging.properties

                         

                        this results in everything beeing logged to /tmp/my.log

                        That really sounds like a bug, unless your log4j properties syntax is wrong.  Could you please file an issue at https://issues.jboss.org/browse/AS7 in the logging component?  In the meantime you should be able to use logging.properties as a workaround to configure your deployment logging; both styles configure the same logging system, just with different syntaxes.  In any case both slf4j and commons-logging are fully supported.

                        • 9. Re: AS7 Logging - org.jboss.logging.jul-to-slf4j-stub ?
                          David Lloyd Master

                          Patrick Ruckstuhl wrote:

                           

                          Forgot to add this, if log in my application directly using the l4j api, this (and only this) shows up in /tmp/my.log

                          Yeah, definitely a bug then.  If you have a log4j.properties then everything should be logged according to that config - even JUL and wrapper frameworks.

                          • 10. Re: AS7 Logging - org.jboss.logging.jul-to-slf4j-stub ?
                            Patrick Ruckstuhl Newbie

                            Thanks, I opened up the bug

                             

                            https://issues.jboss.org/browse/AS7-5255

                             

                            Even with logging.properties there seems to be an issue and I'm wondering if this might be related

                             

                            Configuring the root logger works fine, but it does not work to configure categories

                             

                            https://community.jboss.org/thread/203159

                             

                            Interesting is also that I tried even to debug into the loading of the configuration (breakpoint in PropertyConfigurator) and this sometimes resulted in the thing actually working, I'm wondering if there could be some timing issue with this file (or the general deployment specifc log configurations) beeing loaded.