0 Replies Latest reply on Feb 7, 2008 7:36 AM by anny_lut

    log4j configuration for different filelogs

    anny_lut

      In my session bean I use object of Parent class:


      public class Parent{
       protected static Logger log;
      
       public Parent(String log4jCategory){
       log =Logger.getLogger(log4jCategory);
       }
      
       ....
      }
      
      public class ChildA extends Parent {
       ....
      }
      
      public class ChildB extends Parent {
      ....
      }
      
      
      
      
      public class MyBean implements javax.ejb.SessionBean {
       private Parent obj;
       ....
       public void initParentObject(String paramValue){
       if (paramValue.equals("A"))
       obj = new ChildA("CategoryA");
       else
       obj = new ChildB("CategoryB");
       }
       ....
      }
      
      


      Is it possible to get log data to diferrent file depending on Child class realization.

      Of course, it can be done in such way in log4j.xml:
      
       <appender name="CHILD_A"
       .....
       </appender>
      
       <appender name="CHILD_B"
       .....
       </appender>
      
      
       <category name="mypack.ChildA">
       <appender-ref ref="CHILD_A"/>
       </category>
      
       <category name="mypack.ChildB">
       <appender-ref ref="CHILD_B"/>
       </category>
      
      



      But in reallife realization, there are a lot of classes in ChildA and ChildB
      from different packs, which has their Loggers and they have to write to the same file. That's why I cannot use many different categories in log4j.xml putting only classpath like "mypack.ChildB"


      As I see in wiki "Separating Application Logs", I can use CLFilter:


      <filter class="org.jboss.logging.filter.TCLFilter>
       <param name="AcceptOnMatch" value="true">
       <param name="DeployURL" value="app1.ear">
      


      But here I have to put a EAR name// but in my examle - I want to have 2 different logs in same bean.

      We use JBOSS 3.2.1