Update of /cvsroot/freenet/freenet/src/freenet/support
In directory sc8-pr-cvs1:/tmp/cvs-serv29000/src/freenet/support
Modified Files:
LoggerHook.java
Log Message:
implement selective logging
Index: LoggerHook.java
===================================================================
RCS file: /cvsroot/freenet/freenet/src/freenet/support/LoggerHook.java,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -r1.6 -r1.7
--- LoggerHook.java 5 Jan 2003 12:06:18 -0000 1.6
+++ LoggerHook.java 10 Sep 2003 20:46:14 -0000 1.7
@@ -1,9 +1,24 @@
package freenet.support;
+import java.util.StringTokenizer;
+import java.util.Vector;
+
public abstract class LoggerHook {
public int threshold;
-
+
+ public static final class DetailedThreshold {
+ final String section;
+ final int threshold;
+ public DetailedThreshold(String section, int threshold) {
+ this.section = section;
+ this.threshold = threshold;
+ }
+ }
+
+ public DetailedThreshold[] detailedThresholds =
+ new DetailedThreshold[0];
+
/** These indicate the verbosity levels for calls to log() **/
/** This message indicates an error which prevents correct functionality**/
@@ -36,15 +51,8 @@
public abstract long anyFlags(); // accept if any of these bits set
- public boolean acceptPriority(int prio)
- {
- long mf = minFlags();
- long nf = notFlags();
- long af = anyFlags();
- if ((prio & mf) != mf) return false;
- if ((prio & nf) != 0) return false;
- if ((prio & af) != 0) return true;
- return false;
+ public boolean acceptPriority(int prio) {
+ return prio >= threshold;
}
/**
@@ -54,5 +62,48 @@
public void setThreshold(int thresh) {
this.threshold = thresh;
}
-
+
+ public void setDetailedThresholds(String details) {
+// System.err.println("Setting detailed thresholds for "+this+
+// ": "+details);
+ if(details == null || details.length() == 0) return;
+ StringTokenizer st = new StringTokenizer(details,",",false);
+ Vector stuff = new Vector();
+ while(st.hasMoreTokens()) {
+ String token = st.nextToken();
+// System.err.println("Got token: "+token);
+ if(token.length() == 0) continue;
+ int x = token.indexOf(':');
+ if(x < 0) continue;
+ if(x == token.length() - 1) continue;
+ String section = token.substring(0, x);
+ String value = token.substring(x+1, token.length());
+ int thresh = Logger.priorityOf(value);
+// System.err.println("Pair: "+section+" : "+value);
+ stuff.add(new DetailedThreshold(section, thresh));
+ }
+ DetailedThreshold[] newThresholds =
+ new DetailedThreshold[stuff.size()];
+ stuff.toArray(newThresholds);
+ detailedThresholds = newThresholds;
+ }
+
+ public boolean shouldLog(int priority, Class c) {
+ int thresh = threshold;
+ if(c != null) {
+ String cname = c.getName();
+ if(detailedThresholds.length > 0) {
+ for(int i=0;i<detailedThresholds.length;i++) {
+ DetailedThreshold dt = detailedThresholds[i];
+ if(cname.startsWith(dt.section))
+ threshold = dt.threshold;
+ }
+ }
+ }
+ return priority >= thresh;
+ }
+
+ public final boolean shouldLog(int prio, Object o) {
+ return shouldLog(prio, o.getClass());
+ }
}
_______________________________________________
cvs mailing list
[EMAIL PROTECTED]
http://dodo.freenetproject.org/cgi-bin/mailman/listinfo/cvs