You are viewing a plain text version of this content. The canonical link for it is here.
Posted to log4j-user@logging.apache.org by Julie F McCabe <mc...@jpmorgan.com> on 2001/02/13 15:43:03 UTC

configuring appenders

Hi all,

I have managed to get very confused with log4j & seem to be missing the
efficiency it has to offer.  My problem is I have created my own category, the
aim is to write to 4 different files with the respective cat1 - cat4 categorties
and the console category for writting to system.out for debugging purposes only.
Therefore in the config file below, if I comment out log4j.category.console.cat
= INFO then I should have no logging to system.out, right?  However, the
particular implementation does not work as expected.  Any suggestions?
Basically I want to have a category that I can switch off from the config file
once the program goes into production.

Thanks,
Julie Mc Cabe


config file:

log4j.categoryFactory=com.jpmorgan.researchcontent.transmit.TransmitCategoryFactory
log4j.rootCategory=debug

log4j.category.console.cat = INFO
log4j.category.com.jpmorgan.researchcontent.transmit.cat1.cat=WARN
log4j.category.com.jpmorgan.researchcontent.transmit.cat2.cat=WARN
log4j.category.com.jpmorgan.researchcontent.transmit.cat3.cat=WARN
log4j.category.com.jpmorgan.researchcontent.transmit.cat4.cat=WARN



source code:

to create the default logging parameters
static public void createCategory(String className) {

      PropertyConfigurator.configure(configFile);

      Category root = Category.getRoot();

      console = (TransmitCategory)TransmitCategory.getInstance("console");
      console.addAppender(new FileAppender(new PatternLayout("%-5d %-5x Msg:
%m%n"), System.out));
      console.setPriority(org.apache.log4j.Priority.INFO);
      console.setAdditivity(false);*/


      cat = (TransmitCategory)TransmitCategory.getInstance(className);
      try {
           cat.addAppender(new FileAppender(layout, default, false));
          cat.setPriority(org.apache.log4j.Priority.WARN);
      } catch(IOException e) {e.printStackTrace();}

  }



 to add different categories
 static public void appendToRoot(String system, String className, String
filename) {
      String filename = "";

    try {

        cat = (TransmitCategory)TransmitCategory.getInstance(className);
        file = new FileAppender(layout, filename, true);
        cat.addAppender(file);
        cat.setPriority(org.apache.log4j.Priority.WARN);
        } catch(ClassCastException e) {
      e.printStackTrace();
    }
    catch(IOException e) {
      e.printStackTrace();
    }



This communication is for informational purposes only.  It is not intended as
an offer or solicitation for the purchase or sale of any financial instrument
or as an official confirmation of any transaction. All market prices, data
and other information are not warranted as to completeness or accuracy and
are subject to change without notice. Any comments or statements made herein
do not necessarily reflect those of J.P. Morgan Chase & Co. Incorporated, its
subsidiaries and affiliates.