4 Replies Latest reply on Dec 10, 2013 3:47 PM by neeraj patil

    Adding log4j categories and appenders to jboss logging subsystem for jboss 7.x

    neeraj patil Newbie

      Hi,

       

      I do not want to maintain a separate configuration file for logging (log4j.xml or log4j.properties). So, is it possible that I could log4j specific logging details to the logging subsystem used in Jboss?

      From what I have read so far; I am guessing that is probably not possible.

       

      Thank you

        • 1. Re: Adding log4j categories and appenders to jboss logging subsystem for jboss 7.x
          James Perkins Master

          If you want to use log4j as a logging facade all you need to do is ensure you don't have a log4j configuration file in your deployment and don't include a log4j library in your deployment. As long as you do those two things it should work without a problem and the configuration in the logging subsystem will be used.

           

          --

          James R. Perkins

          • 2. Re: Adding log4j categories and appenders to jboss logging subsystem for jboss 7.x
            neeraj patil Newbie

            Hi James,

             

            Thanks for the reply. I will just elaborate the question more. I want to add the log4j specific properties to the logging subsystem in the jboss server standalone.xml file.

             

            Some example properties are :

             

            # Set Category specific property

            log4j.category.kodo.MetaData=INFO

            # Set appender specific options
            log4j.appender.MaxFileSize=10mb

             

             

            From what I understand from your solution on this question Re: jboss-eap-6.1 + log4j configuration ; that it is not possible.

             

            Like adding something like :

            <appender name="App1Log" class="org.apache.log4j.FileAppender">
              <errorHandler 
              class="org.jboss.logging.util.OnlyOnceErrorHandler"/>
              <param name="Append" value="false"/>
              <param name="File"
              value="${jboss.server.home.dir}/log/app1.log"/>
              <layout class="org.apache.log4j.PatternLayout">
              <param name="ConversionPattern"
              value="%d{ABSOLUTE} %-5p [%c{1}] %m%n"/>
              </layout>
              </appender>

            Is this configuration valid for Jboss EAP 6.1 ?

            Thanks

            • 3. Re: Re: Adding log4j categories and appenders to jboss logging subsystem for jboss 7.x
              James Perkins Master

              Ah gotcha, no that won't work. However you can use the logging subsystem to do the same thing you're doing. The configuration would look like;

                      <subsystem xmlns="urn:jboss:domain:logging:1.2">
                        ...
                        <!-- defines a rotating file handler -->
                        <size-rotating-file-handler name="App1Log" autoflush="true">
                          <file relative-to="jboss.server.log.dir" path="app1.log"/>
                          <formatter>
                            <pattern-formatter pattern="%d{HH:mm:ss,SSS} %-5p [%c{1}] %m%n"/>
                          </formatter>
                          <rotate-size value="10mb"/>
                          <max-backup-index value="5"/>
                          <append value="false"/>
                        </size-rotating-file-handler>
              
              
                        <!-- defines a logger -->
                        <logger category="kodo.MetaData">
                          <level name="INFO"/>
                        </logger>
                        ...
                      </subsystem>
              
              
              

               

              I would however suggest having a look at adding loggers and handlers using CLI or the web console. CLI has tab complete which makes it very useful IMO.

               

              With EAP 6 you can use log4j appenders as custom-handler's. I would however suggest if you're just using file handlers or a console handler use the provided handlers. They will be more efficient.

               

              --

              James R. Perkins