8 Replies Latest reply on Mar 19, 2013 2:28 PM by jamezp

    AS 7.2.0.Final Log4j console logging

    suikast42

      Hi guys,

       

      I try to configure log4j1.2.16 in JBoss 7.2.0.Final.

       

      For that I exclude log4j which is shipped by jbooss from my deployment.

       

       

      <jboss-deployment-structure>
          <!-- <ear-subdeployments-isolated>true</ear-subdeployments-isolated> -->
      
          <deployment>
              <exclusions>
                  <module name="org.apache.log4j" />
              </exclusions>
      
          </deployment>
              <sub-deployment name="modulex.jar">
                 <exclusions>
                     <module name="org.apache.log4j" />
                 </exclusions>
             </sub-deployment>
              <sub-deployment name="moduley.jar">
                 <exclusions>
                     <module name="org.apache.log4j" />
                 </exclusions>
             </sub-deployment>
      </jboss-deployment-structure>
      

       

       

      So the log files are correct. But the annoying thing is the format in the console.

       

      I get for example:

      14:16:34,633 INFO  [stdout] (ServerService Thread Pool -- 171) 14:16:34,633 INFO  [AutoStart] TL2_SOCKET.SND addivity of logger false

       

      instead of

      14:16:34,633 INFO  [com.siemag.wan.server.AutoStart] (ServerService Thread Pool -- 171)  TL2_SOCKET.SND addivity of logger false

        • 1. Re: AS 7.2.0.Final Log4j console logging
          suikast42

          Sorry I typed enter before I was ready .

           

          And as I can see this approch to configure log4j in custom way disturbs another libs as well.

           

           

          14:16:36,071 INFO  [stdout] (ServerService Thread Pool -- 172) 14:16:36,055 INFO  [PrettyFilter] PrettyFilter starting up...

           

          14:16:36,086 INFO  [stdout] (ServerService Thread Pool -- 172) 14:16:36,086 INFO  [PrettyFilter] PrettyFilter initialized.

           

          14:16:36,086 INFO  [solder-servlet] (ServerService Thread Pool -- 172) Catch Integration for Servlets enabled

          • 2. Re: AS 7.2.0.Final Log4j console logging
            jamezp

            It's because the log4j ConsoleAppender writes to stdout which is captured by JBoss STDIO and then passed through a logger. Is there a reason you'd rather not use the logging subsystem? You can use log4j appenders as custom-handler's if there is a handler that's missing.

             

            --

            James R. Perkins

            • 3. Re: AS 7.2.0.Final Log4j console logging
              suikast42

              James Perkins schrieb:

               

              It's because the log4j ConsoleAppender writes to stdout which is captured by JBoss STDIO and then passed through a logger.

               

               

                  Ok that behaviour is therefore normal.

               

               

              James Perkins schrieb:

              . Is there a reason you'd rather not use the logging subsystem? You can use log4j appenders as custom-handler's if there is a handler that's missing.

               

              That was exactly the problem. So I can define my loggers and appenders in standalone.xml , right ? Can you povide me an example how can I use log4j appenders in logging subsystem ??

              • 4. Re: AS 7.2.0.Final Log4j console logging
                jamezp

                Here's an example of using a file handler:

                 

                <subsystem xmlns="urn:jboss:domain:logging:1.2">
                    <custom-handler name="log4jAppender" class="org.apache.log4j.FileAppender" module="org.apache.log4j">
                        <formatter>
                            <pattern-formatter pattern="%d{HH:mm:ss,SSS} %-5p [%c] (%t) %s%E%n"/>
                        </formatter>
                        <level name="INFO"/>
                        <properties>
                            <property name="append" value="true"/>
                            <property name="file" value="${jboss.server.log.dir}/log4j.log"/>
                            <property name="immediateFlush" value="true"/>
                        </properties>
                    </custom-handler>
                    <root-logger>
                        <level name="INFO"/>
                        <handlers>
                            <handler name="log4jAppender"/>
                        </handlers>
                    </root-logger>
                </subsystem>
                
                

                 

                --

                James R. Perkins

                • 5. Re: AS 7.2.0.Final Log4j console logging
                  suikast42

                  Hi James,

                   

                  thanks for that example. And what's about a custom log4j appender ? This appender is contained in my ear app.

                  • 6. Re: AS 7.2.0.Final Log4j console logging
                    jamezp

                    There isn't really a way to configure one based on an appender in your deployment. You'd have to use a separate JAR and set it up as a module.

                     

                    --

                    James R. Perkins

                    • 7. Re: AS 7.2.0.Final Log4j console logging
                      suikast42

                      James Perkins schrieb:

                       

                      There isn't really a way to configure one based on an appender in your deployment. You'd have to use a separate JAR and set it up as a module.

                       

                      --

                      James R. Perkins

                       

                      I assume thats the same if I imlement a custom jboss appender ??

                      • 8. Re: AS 7.2.0.Final Log4j console logging
                        jamezp

                        Yeah. The module has to be seen when the logging subsystem boots up, which is well before any deployments happen.

                         

                        --

                        James R. Perkins