Giving a list to log4jdbc.debug.stack.prefix

195 views
Skip to first unread message

Sean LeBlanc

unread,
Mar 17, 2011, 5:22:53 PM3/17/11
to log4jdbc
Is there any way this property could be extended to permit multiple
packages to be given? The problem I'm having is that our application
has multiple "roots" of packages to check.

I downloaded the source code and took a peek to see where this logic
happens (Slf4jSpyLogDelegator). It appears it must be one package name.

Arthur Blake

unread,
Mar 17, 2011, 5:45:58 PM3/17/11
to log4jdbc
Yes it could be done with a little bit of work. A list of prefixes
could be loaded (similar to the way the log4jdbc.drivers property is
loaded) from a comma delimited string and then the code you mentioned
could be changed to check each item in the list.

Sean LeBlanc

unread,
Mar 29, 2011, 7:18:59 PM3/29/11
to log4jdbc
I ended up modifying a local copy and rebuilding the jdbc-4 jar. Here
is the svn diff:

C:\Users\sleblanc\code\log4jdbc-read-only\src-jdbc4\net\sf
\log4jdbc>svn diff
Index: Slf4jSpyLogDelegator.java
===================================================================
--- Slf4jSpyLogDelegator.java (revision 96)
+++ Slf4jSpyLogDelegator.java (working copy)
@@ -18,6 +18,7 @@
import java.io.IOException;
import java.io.LineNumberReader;
import java.io.StringReader;
+import java.util.List;
import java.util.StringTokenizer;

import org.slf4j.LoggerFactory;
@@ -418,6 +419,20 @@
return out.toString();
}

+ private static boolean somethingInListStartsWith(List<String>
prefixList, String className) {
+ boolean found = false;
+ if (prefixList != null ) {
+ for (String prefix: prefixList) {
+ if (className.startsWith(prefix)){
+ found = true;
+ break;
+ }
+ }
+ }
+
+ return found;
+ }
+
/**
* Get debugging info - the module and line number that called the
logger
* version that prints the stack trace information from the point
just before
@@ -482,8 +497,8 @@
{
firstLog4jdbcCall = i;
}
- else if (DriverSpy.TraceFromApplication &&
- className.startsWith(DriverSpy.DebugStackPrefix))
+ else if (DriverSpy.TraceFromApplication &&
somethingInListStartsWith(DriverSpy.DebugStackPrefix, className))
+ //className.startsWith(DriverSpy.DebugStackPrefix))
{
lastApplicationCall = i;
break;
Index: DriverSpy.java
===================================================================
--- DriverSpy.java (revision 96)
+++ DriverSpy.java (working copy)
@@ -23,13 +23,7 @@
import java.sql.DriverManager;
import java.sql.DriverPropertyInfo;
import java.sql.SQLException;
-import java.util.Enumeration;
-import java.util.HashMap;
-import java.util.Iterator;
-import java.util.Map;
-import java.util.Properties;
-import java.util.Set;
-import java.util.TreeSet;
+import java.util.*;

/**
* A JDBC driver which is a facade that delegates to one or more real
underlying
@@ -109,7 +103,7 @@
* Optional package prefix to use for finding application
generating point of
* SQL.
*/
- static String DebugStackPrefix;
+ static List<String> DebugStackPrefix;

/**
* Flag to indicate debug trace info should be from the calling
application
@@ -318,6 +312,34 @@
return propValue;
}

+ private static List<String> getStringArrayOption(Properties props,
String propName)
+ {
+ String propValue = props.getProperty(propName);
+ List <String>returnValue = new ArrayList<String>();
+ if (propValue == null || propValue.length()==0)
+ {
+ log.debug("x " + propName + " is not defined");
+ returnValue = null; // force to null, even if empty String
+ }
+ else
+ {
+ log.debug(" " + propName + " = " + propValue);
+ String [] tmpList = propValue.split(",");
+ if (tmpList != null) {
+ for (int i=0; i<tmpList.length; i++ ) {
+ returnValue.add(tmpList[i].trim());
+ }
+ }
+ else {
+ returnValue.add(propName.trim());
+ }
+
+ }
+
+
+ return returnValue;
+ }
+
/**
* Get a boolean option from a property and
* log a debug message about this.
@@ -396,7 +418,7 @@
}

// look for additional driver specified in properties
- DebugStackPrefix = getStringOption(props,
"log4jdbc.debug.stack.prefix");
+ DebugStackPrefix = getStringArrayOption(props,
"log4jdbc.debug.stack.prefix");
TraceFromApplication = DebugStackPrefix != null;

Long thresh = getLongOption(props,
"log4jdbc.sqltiming.warn.threshold");
Reply all
Reply to author
Forward
0 new messages