2 Replies Latest reply on Jan 15, 2016 7:41 AM by Ramesh Mishra

    How to configure log4j to in ear to log application specific loggers in a separate file

    Ramesh Mishra Newbie

      Hi, So far i have done the below changes to make my loggers go to a separate log file, the JBoss version is 6.1.

       

      1. Below log4j.xml has been put into META-INF dir in my ear

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

       

       

      <!DOCTYPE log4j:configuration SYSTEM "log4j.dtd"> 

      <log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/"> 

         

       

      <appender name="customAppender" class="org.apache.log4j.ConsoleAppender">

      <param name="Target" value="System.out"/>

      <layout class="org.apache.log4j.PatternLayout">

      <param name="ConversionPattern" value="%d{yyyy-MM-dd HH:mm:ss} %-5p %c{1}:%L - %m%n" />

      </layout>

        </appender>

       

         

      <appender name="customMDBAppender" class="org.apache.log4j.DailyRollingFileAppender"> 

             

      <errorHandler class="org.jboss.logging.util.OnlyOnceErrorHandler"/> 

             

      <param name="Append" value="true"/> 

             

      <param name="File" value="/home/vmdev6/smp53/domains/vmdev/mdb.log"/> 

             

      <layout class="org.apache.log4j.PatternLayout"> 

                 

      <param name="ConversionPattern" value="%d{dd.MM.yyyy HH:mm:ss.SSS} [%C{1}] - %m%n"/> 

             

      </layout> 

         

      </appender> 

         

      <category name="com.abc.samp.imp.xyz.ejb.notificationHandlerMdb" additivity="false"> 

             

      <priority value="INFO"/> 

             

      <appender-ref ref="customMDBAppender"/>

             

      <appender-ref ref="customAppender"/> 

         

      </category> 

         

      <root>

      <priority value="INFO"/>

      <appender-ref ref="customMDBAppender"/>

      </root>

      </log4j:configuration>

       

      2. Below jboss-app,xml into META-INF directory

      <jboss-app>

        <loader-repository>org.myapp:loader=MyClassLoader

         <loader-repository-config>java2ParentDelegation=false</loader-repository-config>

        </loader-repository>  

      </jboss-app>

       

      3. i have put my own log4j-1.2.16.jar into the lib directory of EAR

       

      Going throught the forums i found this setup worked for few peoples, Please can anyone point out what i might be missing here. The behaviour after setting up these changes is that no loggers are coming in the servers.log as well as to the specified file in appender from the package com.abc.samp.imp.xyz.ejb.notificationHandlerMdb. In fact the log file i defined in the log4j.xml is not getting created at all in the location.

        • 1. Re: How to configure log4j to in ear to log application specific loggers in a separate file
          Ramesh Mishra Newbie

          Finally, i have to write a custom classes to handle all the loggers, so now using this i am able to separate the logs?Now i am stuck at suppressing the logs which are going to server.log by default. Is there any way by which i can disable jboss interal logging system?

          • 2. Re: How to configure log4j to in ear to log application specific loggers in a separate file
            Ramesh Mishra Newbie

            Final addition to this thread, i tried one more thing which worked, by directly modifying the logging config in domain/host .xml file. After adding my own package and disabling parent handler worked very well. Wasn't aware it to be so simple.

             

            <subsystem xmlns="urn:jboss:domain:logging:1.2">

                            <console-handler name="CONSOLE">

                                <level name="INFO"/>

                                <formatter>

                                    <pattern-formatter pattern="%K{level}%d{HH:mm:ss,SSS} %-5p [%c] (%t) %s%E%n"/>

                                </formatter>

                            </console-handler>

                            <periodic-rotating-file-handler name="FILE" autoflush="true">

                                <formatter>

                                    <pattern-formatter pattern="%p %d{HH:mm:ss} (%t) %c> %m%n"/>

                                </formatter>

                                <file relative-to="jboss.domain.base.dir" path="log/${jboss.server.name}.log"/>

                                <suffix value=".yyyy-MM-dd"/>

                                <append value="true"/>

                            </periodic-rotating-file-handler>

                            <logger category="com.arjuna">

                                <level name="WARN"/>

                            </logger>

                            <logger category="org.apache.tomcat.util.modeler">

                                <level name="WARN"/>

                            </logger>

                            <logger category="org.jboss.as.config">

                                <level name="DEBUG"/>

                            </logger>

                            <logger category="sun.rmi">

                                <level name="WARN"/>

                            </logger>

                            <logger category="jacorb">

                                <level name="WARN"/>

                            </logger>

                            <logger category="jacorb.config">

                                <level name="ERROR"/>

                            </logger>

                            <logger category="com.abc.xyz.imp.ddd.bss" use-parent-handlers="false">

                                <level name="ALL"/>

            <handlers>

                            <handler name="FILE"/>

                        </handlers>

                            </logger>

                            <root-logger>

                                <level name="INFO"/>

                                <handlers>

                                    <handler name="CONSOLE"/>                       

                                </handlers>

                            </root-logger>

                        </subsystem>