Timothy,

This is a known problem. I just added this to the TROUBLESHOOT.html

<p>Wrappers or subclasses of <code>Category</code> need supply their
fully qualified class name to the <code>Category.log</code> method or
to <code>Category.forcedLog</code> methods so that the caller location
information can be extracted correctly.

<p>This approach will work correctly in all cases except if the class
invoking the extended category instance has the same prefix as the
extended category class. For example, calling an instance of
<code>com.foo.BarCategory</code> from the
<code>com.foo.BarCategoryTest</code> class will not yield the correct
caller information. To circumvent this bug, either perform the tests
from a class with a different name or add a dot to the fully qualified
name of the extending class that you supply to
<code>Category.log</code> to <code>Category.forcedLog</code>
methods. For the <code>com.foo.BarCategory</code> example, supply the
string <code>"com.foo.BarCategory."</code>.

Let me know if it helps. Ceki


At 10:54 27.06.2001 -0400, you wrote:
>I believe I may have found a bug/limitation in the LocationInfo class when using
>extended
>categories.
>
>I extended Category naming it BDSCategory.  I also extended Priority naming it
>BDSPriority.
>I also created a new CategoryFactory called BDSCategoryFactory.  They are
>included at
>the end of this document.
>
>I also created a simple test class called BDSCategoryTest.
>
>Here is the test class:
>/////////////////////////////////////////////////////////////////////////////////////////////////////////////
> package com.bankofny.bds.logadmin;
>
> import org.apache.log4j.*;
> import com.bankofny.bds.logadmin.BDSCategory;
> import org.apache.log4j.PatternLayout;
>
>
> public class BDSCategoryTest
> {
>
>    static BDSCategory cat = BDSCategory.getBDSCategory(
>"com.bankofny.bds.logadmin.BDSCategoryTest" );
>
>    public static void main(String[] args)
>    {
>          int i = -1;
>
>          if (cat != null)
>          {
>               cat.debug("This is a debug statement." + ++i);
>               cat.info("This is an info statement." + ++i);
>                    cat.warn("This is a warning statement." + ++i);
>                    cat.error("This is an error statement." + ++i);
>                    cat.fatal("This is a fatal statement." + ++i);
>                    cat.audit("This is a audit statement." + ++i);
>          }
>         }
> }
>
>/////////////////////////////////////////////////////////////////////////////////////////////////////////////
>Here are the results:
>
>2001-06-27 10:03:55,918 DEBUG at
>com.bankofny.bds.logadmin.BDSCategoryTest.main(BDSCategoryTest.java:27)     -
>This is a debug statement.0
>2001-06-27 10:03:55,928 INFO  at
>com.bankofny.bds.logadmin.BDSCategoryTest.main(BDSCategoryTest.java:29)     -
>This is an info statement.1
>2001-06-27 10:03:55,928 WARN  at
>com.bankofny.bds.logadmin.BDSCategoryTest.main(BDSCategoryTest.java:31)     -
>This is a warning statement.2
>2001-06-27 10:03:55,938 ERROR at
>com.bankofny.bds.logadmin.BDSCategoryTest.main(BDSCategoryTest.java:33)     -
>This is an error statement.3
>2001-06-27 10:03:55,938 FATAL at
>com.bankofny.bds.logadmin.BDSCategoryTest.main(BDSCategoryTest.java:35)     -
>This is a fatal statement.4
>2001-06-27 10:03:55,938 AUDIT at com.bankofny.bds.logadmin.BDSCategoryTest.?(
>            ?:?)     - This is a audit statement.5
>
>I started to look into why the '?' appeared (even posted a few questions to this
> list to no avail).
>After days of going crazy, I created a new test class called MyTest.  It is
>identical to the one above
>except for the name of Class and the Category.
>
>Here it is:
>/////////////////////////////////////////////////////////////////////////////////////////////////////////////
> package com.bankofny.bds.logadmin;
>
> import org.apache.log4j.*;
> import com.bankofny.bds.logadmin.BDSCategory;
> import org.apache.log4j.PatternLayout;
>
> public class MyTest
> {
>
>   static BDSCategory cat = BDSCategory.getBDSCategory(
>"com.bankofny.bds.logadmin.MyTest" );
>
>    public static void main(String[] args)
>    {
>          int i = -1;
>
>          if (cat != null)
>          {
>               cat.debug("This is a debug statement." + ++i);
>               cat.info("This is an info statement." + ++i);
>                    cat.warn("This is a warning statement." + ++i);
>                    cat.error("This is an error statement." + ++i);
>                    cat.fatal("This is a fatal statement." + ++i);
>                    cat.audit("This is a audit statement." + ++i);
>          }
>         }
> }
>
>/////////////////////////////////////////////////////////////////////////////////////////////////////////////
>
>Here are the results:
>
>2001-06-27 09:56:52,209 DEBUG at com.bankofny.bds.logadmin.MyTest.main(
>MyTest.java:27)     - This is a debug statement.0
>2001-06-27 09:56:52,229 INFO  at com.bankofny.bds.logadmin.MyTest.main(
>MyTest.java:29)     - This is an info statement.1
>2001-06-27 09:56:52,229 WARN  at com.bankofny.bds.logadmin.MyTest.main(
>MyTest.java:31)     - This is a warning statement.2
>2001-06-27 09:56:52,229 ERROR at com.bankofny.bds.logadmin.MyTest.main(
>MyTest.java:33)     - This is an error statement.3
>2001-06-27 09:56:52,229 FATAL at com.bankofny.bds.logadmin.MyTest.main(
>MyTest.java:35)     - This is a fatal statement.4
>2001-06-27 09:56:52,239 AUDIT at com.bankofny.bds.logadmin.MyTest.main(
>MyTest.java:37)     - This is a audit statement.5
>
>It worked!!!  No damn "?"!!!!!!!!  But why did it work.
>I copied the test and called it MyBDSCategoryTest and here the results:
>
>2001-06-27 10:02:34,571 DEBUG at
>com.bankofny.bds.logadmin.MyBDSCategoryProject.main(MyBDSCategoryProject.java:27)
>
>    - This is a debug statement.0
>2001-06-27 10:02:34,591 INFO  at
>com.bankofny.bds.logadmin.MyBDSCategoryProject.main(MyBDSCategoryProject.java:29)
>
>    - This is an info statement.1
>2001-06-27 10:02:34,591 WARN  at
>com.bankofny.bds.logadmin.MyBDSCategoryProject.main(MyBDSCategoryProject.java:31)
>
>    - This is a warning statement.2
>2001-06-27 10:02:34,591 ERROR at
>com.bankofny.bds.logadmin.MyBDSCategoryProject.main(MyBDSCategoryProject.java:33)
>
>    - This is an error statement.3
>2001-06-27 10:02:34,631 FATAL at
>com.bankofny.bds.logadmin.MyBDSCategoryProject.main(MyBDSCategoryProject.java:35)
>
>    - This is a fatal statement.4
>2001-06-27 10:02:34,631 AUDIT at
>com.bankofny.bds.logadmin.MyBDSCategoryProject.main(MyBDSCategoryProject.java:37)
>
>    - This is a audit statement.5
>
>It still worked.  Huh.  I copied the test class again and called it
>BDSCategoryProject7.
>Here are the results:
>
>2001-06-27 10:05:35,161 DEBUG at
>com.bankofny.bds.logadmin.BDSCategoryProject7.main(BDSCategoryProject7.java:27)
>     - This is a debug statement.0
>2001-06-27 10:05:35,181 INFO  at
>com.bankofny.bds.logadmin.BDSCategoryProject7.main(BDSCategoryProject7.java:29)
>     - This is an info statement.1
>2001-06-27 10:05:35,181 WARN  at
>com.bankofny.bds.logadmin.BDSCategoryProject7.main(BDSCategoryProject7.java:31)
>     - This is a warning statement.2
>2001-06-27 10:05:35,181 ERROR at
>com.bankofny.bds.logadmin.BDSCategoryProject7.main(BDSCategoryProject7.java:33)
>     - This is an error statement.3
>2001-06-27 10:05:35,181 FATAL at
>com.bankofny.bds.logadmin.BDSCategoryProject7.main(BDSCategoryProject7.java:35)
>     - This is a fatal statement.4
>2001-06-27 10:05:35,191 AUDIT at
>com.bankofny.bds.logadmin.BDSCategoryProject7.?(            ?:?)     - This is a
> audit statement.5
>
>Ahh!  It seems that a class that uses an extended Category as its logger can't
>have a name
>that begins with the extended category class.  I looked in the LocationInfo
>class and  narrowed
>it down to  the following line:
>
>     ibegin = s.lastIndexOf( fqnOfCallingClass );
>
>I guess it was looking for the last occurence of BDSCategory and found the last
>line of the
>stacktrace instead of the second o last line, which caused everything to be
>offset.
>
>It doesn't occur if you use Category and not the extended version.
>
>Regards,
>Tim Grotenhuis
>
>
>CLASSES FOLLOW:
>/////////////////////////////////////////////////////////////////////////////////////////////////////////////
>package com.bankofny.bds.logadmin;
>
>import org.apache.log4j.Category;
>import org.apache.log4j.spi.CategoryFactory;
>
>/**
>* $Id:  $
>*
>* @author Tim Grotenhuis
>* @version $Revision: $
>**/
>public class BDSCategoryFactory implements CategoryFactory
>{
>     /**
>    * The constructor should be public as it will be called by
>    * configurators in different packages.
>    **/
>     public BDSCategoryFactory()
>     {
>    }
>
>     /**
>    * Add Comment Here
>    **/
>    public Category makeNewCategoryInstance( String name )
>    {
>          return new BDSCategory( name );
>    }
>
> }
>/////////////////////////////////////////////////////////////////////////////////////////////////////////////
>package com.bankofny.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 Tim Grotenhuis
>* @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);
>     }
>
>}
>/////////////////////////////////////////////////////////////////////////////////////////////////////////////
>package com.bankofny.bds.logadmin;
>
>import org.apache.log4j.Category;
>import org.apache.log4j.spi.CategoryFactory;
>import org.apache.log4j.spi.LoggingEvent;
>import com.bankofny.bds.logadmin.BDSPriority;
>
>/**
>* $Id:  $
>*
>* @author Tim Grotenhuis
>* @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 BDSCategoryFactory factory = new BDSCategoryFactory();
>
>     /**
>     * Comment needed
>     **/
>     public 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 );
>     }
>
>     /**
>     * This method overrides {@link Category#getInstance} by supplying
>     * its own factory type as a parameter.
>     **/
>     public static BDSCategory getBDSCategory( Class clazz )
>     {
>          return (BDSCategory) getInstance( clazz );
>     }
>
>     /**
>     * We introduce a new printing method that takes the AUDIT priority.
>     **/
>     public void audit( Object message, Throwable t )
>     {
>     if( hierarchy.isDisabled( BDSPriority.AUDIT_INT ) )
>     {
>          return;
>          }
>
>     if( BDSPriority.AUDIT.isGreaterOrEqual( this.getChainedPriority() ) )
>     {
>          forcedLog( FQCN, BDSPriority.AUDIT, message, t );
>          }
>    }
>
>     /**
>     * We introduce a new printing method that takes the AUDIT priority.
>     **/
>     public void audit( Object message )
>     {
>          if( hierarchy.isDisabled( BDSPriority.AUDIT_INT ) )
>          {
>               return;
>          }
>
>          if( BDSPriority.AUDIT.isGreaterOrEqual( this.getChainedPriority() ) )
>          {
>          forcedLog( FQCN, BDSPriority.AUDIT, message, null );
>          }
>     }
>}
>
>
>
>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]

--
Ceki Gülcü


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

Reply via email to