3 Replies Latest reply on May 9, 2013 5:37 AM by petal1

    Configuring log4j LoggerFactory using jboss-logging.xml

    vijaycruise

      Hi All

       

      I am using jboss-logging.xml to configure server-wide logging in JBoss AS 6.0 Final. I was able to get log4j appender working after applying the patch from https://issues.jboss.org/browse/JBAS-8791 . However I couldn't configure the LoggerFactory for log4j. I have my own LoggerFactory that overrides log4j's LoggerFactory and this is how I used to configure log4j.xml with jboss 4.x.

       

          <categoryFactory class="com.my.log.MyLoggerFactory">

              <param name="messageBundle" value="MyLoggerBundle"/>

          </categoryFactory>

       

      I read the xsd for jboss-logging.xml and I couldn't find a reference to LoggerFactory there  - http://anonsvn.jboss.org/repos/jbossas/projects/logging-service-metadata/trunk/src/main/resources/META-INF/schema/jboss-logging_6_0.xsd .

       

      If anyone knows how to configure LoggerFactory using jboss-logging.xml, kindly let me know.

       

      Regards

      Vijay

        • 1. Re: Configuring log4j LoggerFactory using jboss-logging.xml
          petal1

          Hi Vijay,

           

          I know your post is an old one, but did you ever find an answer to your question?

           

          Also, I am struggling to get the log4j appenders working in my JBoss 6.1.0.Final environment. I see that you have managed and I'm interested to know what you had to do. I too have applied the 8791 patch (even though it shouldn't have been necessary in 6.1.0). I have a simple. I have jboss-logging.xml with a simple appender configured like this, but I see nothing in serverx.log (in fact it is not even created):

           

          <log4j-appender name="MYTEMPFILE" class="org.apache.log4j.RollingFileAppender">
             
          <error-manager>
                 
          <only-once/>
             
          </error-manager>

             
          <level name="DEBUG"/>

             
          <properties>
                 
          <property name="file">${jboss.server.home.dir}/log/serverx.log</property>
                 
          <property name="maximumFileSize">20480000</property>
                 
          <property name="maxBackupIndex">5</property>
             
          </properties>

             
          <formatter>
                 
          <pattern-formatter pattern="%d %-5p [%c] (%t) %m%n"/>
             
          </formatter>

          </log4j-appender>
          <!-- tried this too
          <logger category="com.myco">
             <level name="DEBUG"/>
             <handlers>
                <handler-ref name="MYTEMPFILE"/>
             </handlers>
          </logger>
          -->

          ...
          <root-logger>
             
          <!-- Set the root logger priority via a system property, with a default value. -->
             
          <level name="${jboss.server.log.threshold:DEBUG}"/>
             
          <handlers>
                 
          <handler-ref name="MYTEMPFILE"/>
                 
          <handler-ref name="CONSOLE"/>
                 
          <handler-ref name="FILE"/>
             
          </handlers>
          </root-logger>

           

          I've tried getting information from the forums, from the documentation (well, what there is of it !!).

           

          Did you have to reference your appender in bin/logging.properties maybe?

           

          Thanks,

          Paul

          • 2. Re: Configuring log4j LoggerFactory using jboss-logging.xml
            vijaycruise

            Applying what I have to your example:

             

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

            <logging xmlns="urn:jboss:logging:6.0" xmlns:b="urn:jboss:bean-deployer:2.0">

             

            <log4j-appender name="MYTEMPFILE" class="org.apache.log4j.RollingFileAppender">
               
            <error-manager>
                   
            <only-once/>
               
            </error-manager>

               
            <level name="DEBUG"/>

               
            <properties>
                   
            <property name="file">${jboss.server.home.dir}/log/serverx.log</property>
                   
            <property name="maxFileSize">20MB</property>
                   
            <property name="maxTotalSize">100MB</property>

               
            </properties>

               
            <formatter>
                   
            <pattern-formatter pattern="%d %-5p [%c] (%t) %m%n"/>
               
            </formatter>

            </log4j-appender>
            <!-- tried this too
            <logger category="com.myco">
               <level name="DEBUG"/>
               <handlers>
                  <handler-ref name="MYTEMPFILE"/>
               </handlers>
            </logger>
            -->

            ...
            <root-logger>
               
            <!-- Set the root logger priority via a system property, with a default value. -->
               
            <level name="${jboss.server.log.threshold:DEBUG}"/>
               
            <handlers>
                   
            <handler-ref name="MYTEMPFILE"/>
                   
            <handler-ref name="CONSOLE"/>
                   
            <handler-ref name="FILE"/>
               
            </handlers>
            </root-logger>

             

            </logging>

             

            so basically,

                1) I was not sure whether you had the <logging></logging> tags.

                 2) Couple of properties in the log4j appender has changed - maxFileSize and maxTotalSize. 20MB and 100MB means we will have a max of 5 files with 20MB each.

                 3) I don't have a level at the <root-logger>, I don't see that in the xsd I have linked in the original post either. It may not work.

             

            try these, it should work.

             

            Regards,

            Vijay

            • 3. Re: Configuring log4j LoggerFactory using jboss-logging.xml
              petal1

              Hi Vijay,

               

              Thank you for replying.

               

              I didn't show the full jboss-logging.xml file in my post, and it turns out the problem I am seeing is caused by the inclusion of another log4j appender. If I remove that one, my file appender works ok.

               

              The problem in the other appender is something to do with setting properties. I removed all my properties from the log4j-appender definition and added them back in 1 by 1. The first three worked fine, but as soon as I add my fourth property in, it breaks. The first three take a long as a parameter, the fourth takes an int. So it may be something to do with that, or it may be to do with the case of the property name - the setter method in my code is called setRMIPort so I have named the property rMIPort, i.e. I have lower-cased the first letter of the part after the 'set' - the same as I have done for the three properties that do work.

               

              Anyway, it seems this is now not related to what you were experiencing.

               

              Thank you,

              Paul