Hi.  This patch to commons logging allow you to specify which methods
in the call stack are uninteresting when using the JDK1.4 Logger. In
Tomcat this seems to be all methods named "log" and "internalLog."  This
is based on Costin's idea of uninteresting classes, but seems to work
better for method names (in Tomcat anyway.)

It is something of a back door.  It is primarily for projects that
are in the process of converting to using commons-logging.

You use it like this,

    LogFactory.getFactory().setAttribute(
                           "commons-logging.wrapperMethods",
                           "log,internalLog" );

    Log log = LogFactory.getLog( "Logger'sName" );

    log.info("Hello World");
 

Is this an acceptable change to commons-logging ?

Cheers,
-bob

P.S. this patch is updated from the one posted to tomcat-dev



On Tue, 2002-07-23 at 15:03, Bob Herrmann wrote:
> On Mon, 2002-07-22 at 14:18, [EMAIL PROTECTED] wrote:
> > 
> > I think there is a simpler solution for this class of problems, and 
> > that would also work with log4j and doesn't require _any_ API
change.
> > ( only changes to the adapter implementations )
> > 
> > Any 'wrapper' will use:
> >   factory=LogFactory.getFactory();
> >    
> >   factory.setAttribute( "commons-logging.wrapperClass", 
> >                         "[CLASSNAME-OF-WRAPPER]");
> >   factory.getLog(), etc.
> 



On Tue, 2002-07-23 at 15:46, [EMAIL PROTECTED] wrote:
> > 1.  For Log4J at least, the wrapper class is 'given' to the logger 
> > implementation via a constructor argument.
> 
> No, it is passed on each call. Log4j is the easiest, it has all the 
> support we need. 
> 
> > 1.a.  Log.setLogWrapper/setAttribute isn't enough.  Putting aside 
> > design/style arguments, it's to late.  Granted this COULD be worked around 
> 
> The only reason for setAttribute on Log is that if we set the
> wrapper on the factory, this will be 'global'. In tomcat we have 
> 2-3 wrappers that are used - and if each will use commons-logging
> we'll need to do some tricks.
> 
> > 2.  In an environment where we have multiple components using 
> > commons-logging, some may wrap - others may not.  A Factory.setAttribute 
> > is dangerous here (it's potentially 'global' across multiple components). 
> > Note also the the attributes are (pre-)loaded out of a properties file.
> 
> I agree.
> 
> 
> > 3.  We need an analogous method (setWrapper or setAttribute) for the 
> > Discovery mechanism.  A requirement for 'setWrapper' would seem to be 
> > fairly specific to logging, it doesn't appear to be generally useful in a 
> > 'discovery' tool.
> 
> I don't think so - this is very specific to logging, it has 
> nothing to do with discovery.
> 
> 
> > (2) is a strong vote for 'LogFactory.getInstance(Class wrapper, 
> > [String|Class] cat)', in addition to the current 'getInstance' methods - 
> > and a vote against a 'setAttribute' in a singleton (global) Factory.
> 
> I think setAttribute on Log would solve (2).
> 
> Costin
> 
> 
> --
> To unsubscribe, e-mail:   <mailto:[EMAIL PROTECTED]>
> For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>

Index: src/java/org/apache/commons/logging/impl/Jdk14Logger.java
===================================================================
RCS file: /home/cvspublic/jakarta-commons/logging/src/java/org/apache/commons/logging/impl/Jdk14Logger.java,v
retrieving revision 1.4
diff -u -r1.4 Jdk14Logger.java
--- src/java/org/apache/commons/logging/impl/Jdk14Logger.java	17 Jul 2002 16:42:40 -0000	1.4
+++ src/java/org/apache/commons/logging/impl/Jdk14Logger.java	23 Jul 2002 20:49:11 -0000
@@ -65,8 +65,11 @@
 
 import java.util.logging.Level;
 import java.util.logging.Logger;
+import java.util.Hashtable;
+import java.util.StringTokenizer;
 
 import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
 
 
 /**
@@ -95,6 +98,14 @@
 
         logger = Logger.getLogger(name);
 
+        String wrapperMethods = (String) LogFactory.getFactory().getAttribute("commons-logging.wrapperMethods");
+        if ( wrapperMethods != null ){
+            StringTokenizer st = new StringTokenizer(wrapperMethods,",");
+            while (st.hasMoreTokens()) {
+                wrapperMethodsHash.put( st.nextToken(), "F" );
+            }
+        }
+
     }
 
 
@@ -106,6 +117,11 @@
      */
     protected Logger logger = null;
 
+    /**
+     * The methods that we ignore in the stack trace
+     */
+    private Hashtable wrapperMethodsHash = new Hashtable();
+
 
     // --------------------------------------------------------- Public Methods
 
@@ -116,10 +132,17 @@
         // Caller will be the third element
         String cname="unknown";
         String method="unknown";
-        if( locations!=null && locations.length >2 ) {
-            StackTraceElement caller=locations[2];
-            cname=caller.getClassName();
-            method=caller.getMethodName();
+        if( locations!=null && locations.length>2 ) {
+            StackTraceElement caller=null;
+            for (int stackLevel=2;stackLevel<locations.length;stackLevel++){
+                caller = locations[stackLevel];
+                cname = caller.getClassName();
+                method = caller.getMethodName();
+                if ( wrapperMethodsHash.get( method ) == null ){
+                    break;
+                } 
+
+            }
         }
 
         if( ex==null ) {

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

Reply via email to