I've extended Category and Priority to add a new Priority called AUDIT (higher
than FATAL).
I used both the XCategory and XPriority as examples, as well as the AppServer
example.
I modified XTest.java to run my changes and used a modified sort1.lcf file as
the
properties files.

Here is the output:

2001-06-22 14:24:55,520 DEBUG at some.cat.sample(BDSCategoryTest.java:61)     -
Message 0
2001-06-22 14:24:55,530 WARN  at some.cat.sample(BDSCategoryTest.java:62)     -
Message 1
2001-06-22 14:24:55,530 ERROR at some.cat.sample(BDSCategoryTest.java:63)     -
Message 2
2001-06-22 14:24:55,540 FATAL at some.cat.sample(BDSCategoryTest.java:64)     -
Message 3
2001-06-22 14:24:55,540 AUDIT at some.cat.?(            ?:?)     - Message 4


Why am I getting the "?" instead of what I want?  Any help would be appreciated.

Thanks in advance,
Tim
-------------------------------------------------------------------------------------

Here is the Test class:

public class BDSCategoryTest {

  public static BDSCategory cat = BDSCategory.getBDSCategory("some.cat");

  public
  static
  void main(String argv[]) {

    if(argv.length == 1)
      init(argv[0]);
    else
      Usage("Wrong number of arguments.");
    sample();
  }

  static
  void Usage(String msg) {
    System.err.println(msg);
    System.err.println( "Usage: java " + BDSCategoryTest.class.getName() +
               "configFile");
    System.exit(1);
  }

  static
  void init(String configFile) {

    PropertyConfigurator.configure(configFile);
  }

  static
  void sample() {
    int i = -1;


    //Category root = Category.getRoot();
    cat.debug("Message " + ++i);
    cat.warn ("Message " + ++i);
    cat.error("Message " + ++i);
    cat.fatal("Message " + ++i);
    cat.audit("Message " + ++i);
  }

}
-----------------------------------------------------------------------------------------

Here is the sort1.lcf file:

log4j.rootCategory=, A1

# A1 is set to be a ConsoleAppender which outputs to System.out.
log4j.appender.A1=org.apache.log4j.ConsoleAppender

# A1 uses PatternLayout.
log4j.appender.A1.layout=org.apache.log4j.PatternLayout

# The conversion pattern uses format specifiers. You might want to
# change the pattern an watch the output layout change.
log4j.appender.A1.layout.ConversionPattern=%d %-5p at %c{5}.%M(%13F:%L) %3x -
%m\n

--------------------------------------------------------------------------------------
Here is my Priorty class: BDSPriority

/*
 * $Id:  $
 * $Revision: $
 * $Name:  $
*/
package com.yyyyy.bds.logadmin;

import org.apache.log4j.Priority;

/**
* $Id:  $
* This class introduces a new custom priority level for BDS.  It is called
* AUDIT.  It is higher in priority than FATAL.  Recall, the current levels
* are: DEBUG < INFO < WARN < ERROR < FATAL.
*
* This class extends org.apache.log4j.Priority.
*
* @author
* @version $Revision:  $
**/
public class BDSPriority extends Priority
{
     private static final String
         RCS_ID = "$Id:  $";
    private static final String
        RCS_REV = "$Revision: $";
    private static final String
        RCS_NAME = "$Name: $";

     /**
     * Comment needed
     **/
     public static final int AUDIT_INT = Priority.FATAL_INT + 190;

     private static String AUDIT_STR  = "AUDIT";

     /**
     * The <code>AUDIT</code> priority designates information that
     * will always be logged, presumably to the AuditTrail DB.
     * Synonomous with "FATAL"
     **/
     final static public BDSPriority AUDIT = new BDSPriority( AUDIT_INT,
AUDIT_STR, 0 );


     protected BDSPriority( int level, String levelStr, int syslogEquivalent )
    {
          super( level, levelStr, syslogEquivalent );
    }


     /**
     * OVERRIDDEN: To add our new priority level: AUDIT
     * Convert the int passed as an argument to a priority. If the int is not
     * equivalent to one of BDS' new Priority levels, both arguments are
     * passed on to the superclass method, which checks the int value against
     * the built-in priority levels, If the conversion fails in the super-
     * class, then the value of <code>defaultPriority</code> is returned.
     *
      * @param val integer to convert to Priority
      * @param defaultPriority Priority level to use if integer doesn't find
match
     * @return A Priority object
     **/
     public static Priority toPriority(int i) throws  IllegalArgumentException
     {
          if(i == AUDIT_INT)
          {
          return BDSPriority.AUDIT;
          }

     return Priority.toPriority(i);
    }

     /**
     * OVERRIDDEN: To add our new priority level: AUDIT
     * Convert the string passed as an argument to a priority. If the String
     * is not one of BDS' new Priority levels, both arguments are passed
     * on to the superclass method, which checks the String value against
     * the built-in priority levels, If the conversion fails in the super-
     * class, then the value of <code>defaultPriority</code> is returned.
     *
      * @param sArg String to convert to Priority
      * @param defaultPriority Priority level to use if string doesn't find
match
     * @return A Priority object
     **/
     public static Priority toPriority(String sArg, Priority defaultPriority)
     {
     if(sArg == null)
     {
          return defaultPriority;
          }

     String s = sArg.toUpperCase();

     if(s.equals( AUDIT_STR ))
     {
               return BDSPriority.AUDIT;
          }

     return Priority.toPriority(sArg, defaultPriority);
     }

}

------------------------------------------------------------------------------------

Here is my Category class:

/*
* $Id:  $
* $Revision: $
* $Name:  $
*/
package com.yyyyy.bds.logadmin;

import org.apache.log4j.Category;
import org.apache.log4j.spi.CategoryFactory;
import org.apache.log4j.spi.LoggingEvent;
import com.yyyyy.bds.logadmin.BDSPriority;

/**
* $Id:  $
*
* @author
* @version $Revision: $
**/

public class BDSCategory extends Category
{
    private static final String
         RCS_ID = "$Id:  $";
    private static final String
        RCS_REV = "$Revision: $";
    private static final String
        RCS_NAME = "$Name: $";

     /**
     * Comment needed
     **/
     final private static String FQCN = BDSCategory.class.getName();

     /**
     * Comment needed
     **/
     private static BDSFactory factory = new BDSFactory();

     /**
     * Comment needed
     **/
     protected BDSCategory( String name )
     {
     super( name );
    }


     /**
     * This method overrides {@link Category#getInstance} by supplying
     * its own factory type as a parameter.
     **/
     public static Category getInstance( String name )
     {
          return Category.getInstance( name, factory );
     }

     /**
     * This method overrides {@link Category#getInstance} by supplying
     * its own factory type as a parameter.
     **/
     public static BDSCategory getBDSCategory( String name )
     {
          return (BDSCategory) getInstance( name );
     }

     /**
     * This method overrides {@link Category#getInstance(Class)} by supplying
     * its own factory type as a parameter.
     **/
     public static Category getInstance( Class clazz )
     {
          return getInstance( clazz.getName(), factory );
     }

     /**
     * We introduce a new printing method that takes the AUDIT priority.
     **/
     public void audit( String message, Throwable t )
     {
     if( hierarchy.isDisabled( BDSPriority.AUDIT_INT ) )
     {
          return;
          }

     if( BDSPriority.AUDIT.isGreaterOrEqual( this.getChainedPriority() ) )
     {
          //forcedLog( FQCN, BDSPriority.AUDIT, message, t );
          callAppenders( new LoggingEvent( FQCN, this, BDSPriority.AUDIT,
message, null ) );
          }
    }

     /**
     * We introduce a new printing method that takes the AUDIT priority.
     **/
     public void audit(String message)
     {
          if( hierarchy.isDisabled( BDSPriority.AUDIT_INT ) )
          {
               return;
          }

          if( BDSPriority.AUDIT.isGreaterOrEqual( this.getChainedPriority() ) )
          {
          //forcedLog( FQCN, BDSPriority.AUDIT, message, null );
          callAppenders( new LoggingEvent( FQCN, this, BDSPriority.AUDIT,
message, null ) );
          }
     }

     /**
     * $Id:  $
     * Any sub-class of Category must also have its own implementation of
     * CategoryFactory.
     *
     * @author
     * @version $Revision: $
     **/
     public static class BDSFactory implements CategoryFactory
     {
          public BDSFactory()
          {
          }

          public Category makeNewCategoryInstance( String name )
          {
               return new BDSCategory( name );
          }
     }
}




The information in this e-mail, and any attachment therein, is confidential and
for use by the addressee only. If you are not the intended recipient, please
return the e-mail to the sender and delete it from your computer. Although the
Bank of New York attempts to sweep e-mail and attachments for viruses, it does
not guarantee that either are virus-free and accepts no liability for any damage
sustained as a result of viruses.




---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to