You are viewing a plain text version of this content. The canonical link for it is here.
Posted to log4j-dev@logging.apache.org by rg...@apache.org on 2011/08/03 19:07:38 UTC

svn commit: r1153584 - in /logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/main/java/org/apache/logging/log4j/core: appender/rolling/DefaultRolloverStrategy.java config/FileConfigurationMonitor.java config/XMLConfiguration.java

Author: rgoers
Date: Wed Aug  3 17:07:38 2011
New Revision: 1153584

URL: http://svn.apache.org/viewvc?rev=1153584&view=rev
Log:
Add FileMonitor. Remove max window size from RolloverStrategy

Modified:
    logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/main/java/org/apache/logging/log4j/core/appender/rolling/DefaultRolloverStrategy.java
    logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/main/java/org/apache/logging/log4j/core/config/FileConfigurationMonitor.java
    logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/main/java/org/apache/logging/log4j/core/config/XMLConfiguration.java

Modified: logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/main/java/org/apache/logging/log4j/core/appender/rolling/DefaultRolloverStrategy.java
URL: http://svn.apache.org/viewvc/logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/main/java/org/apache/logging/log4j/core/appender/rolling/DefaultRolloverStrategy.java?rev=1153584&r1=1153583&r2=1153584&view=diff
==============================================================================
--- logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/main/java/org/apache/logging/log4j/core/appender/rolling/DefaultRolloverStrategy.java (original)
+++ logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/main/java/org/apache/logging/log4j/core/appender/rolling/DefaultRolloverStrategy.java Wed Aug  3 17:07:38 2011
@@ -61,10 +61,6 @@ import java.util.List;
  */
 @Plugin(name = "DefaultRolloverStrategy", type = "Core", printObject = true)
 public class DefaultRolloverStrategy implements RolloverStrategy {
-    /**
-     * It's almost always a bad idea to have a large window size, say over 12.
-     */
-    private static final int MAX_WINDOW_SIZE = 12;
     private static final int MIN_WINDOW_SIZE = 1;
     private static final int DEFAULT_WINDOW_SIZE = 7;
 
@@ -222,17 +218,8 @@ public class DefaultRolloverStrategy imp
 
     @PluginFactory
     public static DefaultRolloverStrategy createStrategy(@PluginAttr("max") String max,
-                                                             @PluginAttr("min") String min) {
-        int maxIndex;
-        if (max != null) {
-            maxIndex = Integer.parseInt(max);
-            if (maxIndex > MAX_WINDOW_SIZE) {
-                logger.error("Maximum window size too large. Limited to " + MAX_WINDOW_SIZE);
-                maxIndex = MAX_WINDOW_SIZE;
-            }
-        } else {
-            maxIndex = DEFAULT_WINDOW_SIZE;
-        }
+                                                         @PluginAttr("min") String min) {
+
         int minIndex;
         if (min != null) {
             minIndex = Integer.parseInt(min);
@@ -243,7 +230,16 @@ public class DefaultRolloverStrategy imp
         } else {
             minIndex = MIN_WINDOW_SIZE;
         }
-
+        int maxIndex;
+        if (max != null) {
+            maxIndex = Integer.parseInt(max);
+            if (maxIndex < minIndex) {
+                maxIndex = minIndex < DEFAULT_WINDOW_SIZE ? DEFAULT_WINDOW_SIZE : minIndex;
+                logger.error("Maximum window size must be greater than the minimum windows size. Set to " + maxIndex);
+            }
+        } else {
+            maxIndex = DEFAULT_WINDOW_SIZE;
+        }
         return new DefaultRolloverStrategy(minIndex, maxIndex);
     }
 

Modified: logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/main/java/org/apache/logging/log4j/core/config/FileConfigurationMonitor.java
URL: http://svn.apache.org/viewvc/logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/main/java/org/apache/logging/log4j/core/config/FileConfigurationMonitor.java?rev=1153584&r1=1153583&r2=1153584&view=diff
==============================================================================
--- logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/main/java/org/apache/logging/log4j/core/config/FileConfigurationMonitor.java (original)
+++ logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/main/java/org/apache/logging/log4j/core/config/FileConfigurationMonitor.java Wed Aug  3 17:07:38 2011
@@ -24,16 +24,45 @@ import java.util.List;
  */
 public class FileConfigurationMonitor implements ConfigurationMonitor {
 
-    private File file;
+    private final File file;
 
-    private List<ConfigurationListener> listeners;
+    private long lastModified;
 
-    public FileConfigurationMonitor(File file, List<ConfigurationListener> listeners) {
+    private final List<ConfigurationListener> listeners;
+
+    private final int interval;
+
+    private long nextCheck;
+
+    private final static int MIN_INTERVAL = 30;
+
+    private volatile int counter = 0;
+    private static final int MASK = 0x0f;
+    private long start;
+
+    public FileConfigurationMonitor(File file, List<ConfigurationListener> listeners, int interval) {
         this.file = file;
+        this.lastModified = file.lastModified();
         this.listeners = listeners;
+        this.interval = (interval < MIN_INTERVAL ? MIN_INTERVAL : interval) * 1000;
+        this.nextCheck = System.currentTimeMillis() + interval;
+        this.start = System.nanoTime();
     }
 
     public void checkConfiguration() {
-
+        if ((++counter & MASK) == 0) {
+            long current = System.currentTimeMillis();
+            synchronized(this) {
+                if (current >= nextCheck) {
+                    nextCheck = current + interval;
+                    if (lastModified >= file.lastModified()) {
+                        lastModified = file.lastModified();
+                        for (ConfigurationListener listener : listeners) {
+                            listener.onChange();
+                        }
+                    }
+                }
+            }
+        }
     }
 }

Modified: logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/main/java/org/apache/logging/log4j/core/config/XMLConfiguration.java
URL: http://svn.apache.org/viewvc/logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/main/java/org/apache/logging/log4j/core/config/XMLConfiguration.java?rev=1153584&r1=1153583&r2=1153584&view=diff
==============================================================================
--- logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/main/java/org/apache/logging/log4j/core/config/XMLConfiguration.java (original)
+++ logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/main/java/org/apache/logging/log4j/core/config/XMLConfiguration.java Wed Aug  3 17:07:38 2011
@@ -98,7 +98,7 @@ public class XMLConfiguration extends Ba
                 } else if ("monitorInterval".equalsIgnoreCase(entry.getKey())) {
                     int interval = Integer.parseInt(entry.getValue());
                     if (interval > 0 && configFile != null) {
-                        monitor = new FileConfigurationMonitor(configFile, listeners);
+                        monitor = new FileConfigurationMonitor(configFile, listeners, interval);
                     }
                 }
             }



---------------------------------------------------------------------
To unsubscribe, e-mail: log4j-dev-unsubscribe@logging.apache.org
For additional commands, e-mail: log4j-dev-help@logging.apache.org