Author: toad
Date: 2006-08-24 01:28:44 +0000 (Thu, 24 Aug 2006)
New Revision: 10250

Modified:
   trunk/freenet/src/freenet/node/LoggingConfigHandler.java
   trunk/freenet/src/freenet/support/LoggerHook.java
   trunk/freenet/src/freenet/support/LoggerHookChain.java
Log:
Add selective logging support. (logger.detailedThresholds).

Modified: trunk/freenet/src/freenet/node/LoggingConfigHandler.java
===================================================================
--- trunk/freenet/src/freenet/node/LoggingConfigHandler.java    2006-08-24 
01:09:58 UTC (rev 10249)
+++ trunk/freenet/src/freenet/node/LoggingConfigHandler.java    2006-08-24 
01:28:44 UTC (rev 10250)
@@ -15,6 +15,7 @@
 import freenet.support.LoggerHook;
 import freenet.support.LoggerHookChain;
 import freenet.support.FileLoggerHook.IntervalParseException;
+import freenet.support.LoggerHook.InvalidThresholdException;

 public class LoggingConfigHandler {

@@ -92,6 +93,8 @@

        maxZippedLogsSize = config.getLong("maxZippedLogsSize");

+       // These two are forced below so we don't need to check them now
+       
        // priority

        // Node must override this to minor on testnet.
@@ -111,6 +114,28 @@
                                        }
        });

+       // detailed priority
+       
+       config.register("priorityDetail", "", 5, true, "Detailed priority 
thresholds", "Detailed priority thresholds, example 
freenet:normal,freenet.node:minor",
+                       new StringCallback() {
+
+                                       public String get() {
+                                               LoggerHookChain chain = 
Logger.getChain();
+                                               return 
chain.getDetailedThresholds();
+                                       }
+
+                                       public void set(String val) throws 
InvalidConfigValueException {
+                                               LoggerHookChain chain = 
Logger.getChain();
+                                               try {
+                                                       
chain.setDetailedThresholds(val);
+                                               } catch 
(InvalidThresholdException e) {
+                                                       throw new 
InvalidConfigValueException(e.getMessage());
+                                               }
+                                       }
+               
+       });
+       
+       
        // interval

        config.register("interval", "5MINUTE", 5, true, "Log rotation 
interval", "Log rotation interval - period after which logs are rotated. We 
keep the last two log files (current and prev), plus lots of compressed 
logfiles up to maxZippedLogsSize",
@@ -191,6 +216,7 @@
                        Logger.setupChain();
                        try {
                                config.forceUpdate("priority");
+                               config.forceUpdate("priorityDetail");
                        } catch (InvalidConfigValueException e2) {
                                System.err.println("Invalid config value for 
logger.priority in config file: "+config.getString("priority"));
                                // Leave it at the default.

Modified: trunk/freenet/src/freenet/support/LoggerHook.java
===================================================================
--- trunk/freenet/src/freenet/support/LoggerHook.java   2006-08-24 01:09:58 UTC 
(rev 10249)
+++ trunk/freenet/src/freenet/support/LoggerHook.java   2006-08-24 01:28:44 UTC 
(rev 10250)
@@ -134,6 +134,19 @@
                stuff.toArray(newThresholds);
                detailedThresholds = newThresholds;
        }
+
+       public String getDetailedThresholds() {
+               DetailedThreshold[] thresh = detailedThresholds;
+               StringBuffer sb = new StringBuffer();
+               for(int i=0;i<thresh.length;i++) {
+                       if(i != 0)
+                               sb.append(',');
+                       sb.append(thresh[i].section);
+                       sb.append(':');
+                       sb.append(LoggerHook.priorityOf(thresh[i].dThreshold));
+               }
+               return sb.toString();
+       }

     /**
      * Returns the priority level matching the string. If no priority

Modified: trunk/freenet/src/freenet/support/LoggerHookChain.java
===================================================================
--- trunk/freenet/src/freenet/support/LoggerHookChain.java      2006-08-24 
01:09:58 UTC (rev 10249)
+++ trunk/freenet/src/freenet/support/LoggerHookChain.java      2006-08-24 
01:28:44 UTC (rev 10250)
@@ -103,9 +103,10 @@

        public void setDetailedThresholds(String details) throws 
InvalidThresholdException {
                super.setDetailedThresholds(details);
-               LoggerHook[] h = getHooks();
-               for (int i = 0; i < h.length; i++)
-                       h[i].setDetailedThresholds(details);
+               // No need to tell subordinates, we will do the filtering.
+//             LoggerHook[] h = getHooks();
+//             for (int i = 0; i < h.length; i++)
+//                     h[i].setDetailedThresholds(details);
        }
        public void setThreshold(int thresh) {
                super.setThreshold(thresh);


Reply via email to