logging-log4j-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rgo...@apache.org
Subject svn commit: r1104006 - in /logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/main/java/org/apache/logging/log4j/core: appender/ appender/rolling/ filter/
Date Tue, 17 May 2011 05:44:10 GMT
Author: rgoers
Date: Tue May 17 05:44:10 2011
New Revision: 1104006

URL: http://svn.apache.org/viewvc?rev=1104006&view=rev
Log:
remove unneeded imports. Add TimeFilter

Added:
    logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/main/java/org/apache/logging/log4j/core/filter/TimeFilter.java
      - copied, changed from r1074871, logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/main/java/org/apache/logging/log4j/core/filter/ThresholdFilter.java
Modified:
    logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/main/java/org/apache/logging/log4j/core/appender/OutputStreamManager.java
    logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/main/java/org/apache/logging/log4j/core/appender/RollingFileAppender.java
    logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/main/java/org/apache/logging/log4j/core/appender/rolling/CompositeTriggeringPolicy.java
    logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/main/java/org/apache/logging/log4j/core/appender/rolling/RollingFileManager.java

Modified: logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/main/java/org/apache/logging/log4j/core/appender/OutputStreamManager.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/OutputStreamManager.java?rev=1104006&r1=1104005&r2=1104006&view=diff
==============================================================================
--- logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/main/java/org/apache/logging/log4j/core/appender/OutputStreamManager.java
(original)
+++ logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/main/java/org/apache/logging/log4j/core/appender/OutputStreamManager.java
Tue May 17 05:44:10 2011
@@ -16,9 +16,7 @@
  */
 package org.apache.logging.log4j.core.appender;
 
-import com.sun.tools.hat.internal.model.StackTrace;
 import org.apache.logging.log4j.Logger;
-import org.apache.logging.log4j.core.Lifecycle;
 import org.apache.logging.log4j.internal.StatusLogger;
 
 import java.io.IOException;

Modified: logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/main/java/org/apache/logging/log4j/core/appender/RollingFileAppender.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/RollingFileAppender.java?rev=1104006&r1=1104005&r2=1104006&view=diff
==============================================================================
--- logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/main/java/org/apache/logging/log4j/core/appender/RollingFileAppender.java
(original)
+++ logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/main/java/org/apache/logging/log4j/core/appender/RollingFileAppender.java
Tue May 17 05:44:10 2011
@@ -28,9 +28,6 @@ import org.apache.logging.log4j.core.con
 import org.apache.logging.log4j.core.config.plugins.PluginFactory;
 import org.apache.logging.log4j.core.filter.Filters;
 
-import java.util.concurrent.locks.Lock;
-import java.util.concurrent.locks.ReentrantLock;
-
 /**
  *
  */

Modified: logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/main/java/org/apache/logging/log4j/core/appender/rolling/CompositeTriggeringPolicy.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/CompositeTriggeringPolicy.java?rev=1104006&r1=1104005&r2=1104006&view=diff
==============================================================================
--- logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/main/java/org/apache/logging/log4j/core/appender/rolling/CompositeTriggeringPolicy.java
(original)
+++ logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/main/java/org/apache/logging/log4j/core/appender/rolling/CompositeTriggeringPolicy.java
Tue May 17 05:44:10 2011
@@ -17,7 +17,6 @@
 package org.apache.logging.log4j.core.appender.rolling;
 
 import org.apache.logging.log4j.core.LogEvent;
-import org.apache.logging.log4j.core.appender.FileManager;
 import org.apache.logging.log4j.core.config.plugins.Plugin;
 import org.apache.logging.log4j.core.config.plugins.PluginElement;
 import org.apache.logging.log4j.core.config.plugins.PluginFactory;

Modified: logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/main/java/org/apache/logging/log4j/core/appender/rolling/RollingFileManager.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/RollingFileManager.java?rev=1104006&r1=1104005&r2=1104006&view=diff
==============================================================================
--- logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/main/java/org/apache/logging/log4j/core/appender/rolling/RollingFileManager.java
(original)
+++ logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/main/java/org/apache/logging/log4j/core/appender/rolling/RollingFileManager.java
Tue May 17 05:44:10 2011
@@ -30,12 +30,8 @@ import java.io.FileNotFoundException;
 import java.io.FileOutputStream;
 import java.io.IOException;
 import java.io.OutputStream;
-import java.text.SimpleDateFormat;
-import java.util.Date;
 import java.util.concurrent.ArrayBlockingQueue;
 import java.util.concurrent.TimeUnit;
-import java.util.concurrent.locks.Lock;
-import java.util.concurrent.locks.ReentrantLock;
 
 /**
  *

Copied: logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/main/java/org/apache/logging/log4j/core/filter/TimeFilter.java
(from r1074871, logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/main/java/org/apache/logging/log4j/core/filter/ThresholdFilter.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/filter/TimeFilter.java?p2=logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/main/java/org/apache/logging/log4j/core/filter/TimeFilter.java&p1=logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/main/java/org/apache/logging/log4j/core/filter/ThresholdFilter.java&r1=1074871&r2=1104006&rev=1104006&view=diff
==============================================================================
--- logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/main/java/org/apache/logging/log4j/core/filter/ThresholdFilter.java
(original)
+++ logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/main/java/org/apache/logging/log4j/core/filter/TimeFilter.java
Tue May 17 05:44:10 2011
@@ -18,6 +18,7 @@ package org.apache.logging.log4j.core.fi
 
 import org.apache.logging.log4j.Level;
 import org.apache.logging.log4j.Marker;
+import org.apache.logging.log4j.core.Filter;
 import org.apache.logging.log4j.core.LogEvent;
 import org.apache.logging.log4j.core.Logger;
 import org.apache.logging.log4j.core.config.plugins.Plugin;
@@ -25,56 +26,96 @@ import org.apache.logging.log4j.core.con
 import org.apache.logging.log4j.core.config.plugins.PluginFactory;
 import org.apache.logging.log4j.message.Message;
 
+import java.text.ParseException;
+import java.text.SimpleDateFormat;
+import java.util.Calendar;
+import java.util.TimeZone;
+
 /**
- * This filter returns the onMatch result if the level in the LogEvent is the same or more
specific
- * than the configured level and the onMismatch value otherwise. For example, if the ThresholdFilter
- * is configured with Level ERROR and the LogEvent contains Level DEBUG then the onMismatch
value will
- * be returned since ERROR events are more specific than DEBUG.
- *
- * The default Level is ERROR.
+ * Filters events that fall within a specified time period in each day.
  */
-@Plugin(name="Threshold", type="Core", elementType="filter")
-public class ThresholdFilter extends FilterBase {
-
-    private static final String LEVEL = "level";
-
-    private final Level level;
+@Plugin(name="Time", type="Core", elementType="filter")
+public class TimeFilter extends FilterBase {
+    /**
+     * Starting offset from midnight in milliseconds.
+     */
+    private final long start;
+    /**
+     * Ending offset from midnight in milliseconds.
+     */
+    private final long end;
+    /**
+     * Timezone.
+     */
+    private final Calendar calendar;
+
+
+    /**
+     * Length of hour in milliseconds.
+     */
+    private static final long HOUR_MS = 3600000;
+
+    /**
+     * Length of minute in milliseconds.
+     */
+    private static final long MINUTE_MS = 60000;
+
+    /**
+     * Length of second in milliseconds.
+     */
+    private static final long SECOND_MS = 1000;
 
-    private ThresholdFilter(Level level, Result onMatch, Result onMismatch) {
+    private TimeFilter(long start, long end, TimeZone tz, Result onMatch, Result onMismatch)
{
         super(onMatch, onMismatch);
-        this.level = level;
-    }
-
-    public Result filter(Logger logger, Level level, Marker marker, String msg, Object[]
params) {
-        return filter(level);
-    }
-
-    public Result filter(Logger logger, Level level, Marker marker, Object msg, Throwable
t) {
-        return filter(level);
-    }
-
-    public Result filter(Logger logger, Level level, Marker marker, Message msg, Throwable
t) {
-        return filter(level);
+        this.start = start;
+        this.end = end;
+        calendar = Calendar.getInstance(tz);
     }
 
     @Override
     public Result filter(LogEvent event) {
-        return filter(event.getLevel());
-    }
-
-    private Result filter(Level level) {
-        return level.isAtLeastAsSpecificAs(this.level) ? onMatch : onMismatch;
+        calendar.setTimeInMillis(event.getMillis());
+        //
+        //   get apparent number of milliseconds since midnight
+        //      (ignores extra or missing hour on daylight time changes).
+        //
+        long apparentOffset = calendar.get(Calendar.HOUR_OF_DAY) * HOUR_MS +
+            calendar.get(Calendar.MINUTE) * MINUTE_MS +
+            calendar.get(Calendar.SECOND) * SECOND_MS +
+            calendar.get(Calendar.MILLISECOND);
+        return (apparentOffset >= start && apparentOffset < end) ? onMatch
: onMismatch;
     }
 
     @PluginFactory
-    public static ThresholdFilter createFilter(@PluginAttr("level") String loggerLevel,
-                                               @PluginAttr("onMatch") String match,
-                                               @PluginAttr("onMismatch") String mismatch)
{
-        Level level = loggerLevel == null ? Level.ERROR : Level.toLevel(loggerLevel.toUpperCase());
+    public static TimeFilter createFilter(@PluginAttr("start") String start,
+                                          @PluginAttr("end") String end,
+                                          @PluginAttr("timezone") String tz,
+                                          @PluginAttr("onMatch") String match,
+                                          @PluginAttr("onMismatch") String mismatch) {
+        SimpleDateFormat stf = new SimpleDateFormat("HH:mm:ss");
+        long s = 0;
+        if (start != null) {
+            stf.setTimeZone(TimeZone.getTimeZone("UTC"));
+            try {
+                s = stf.parse(start).getTime();
+            } catch(ParseException ex) {
+                logger.warn("Error parsing start value " + start, ex);
+            }
+        }
+        long e = 0;
+        if (end != null) {
+            stf.setTimeZone(TimeZone.getTimeZone("UTC"));
+            try {
+                e = stf.parse(end).getTime();
+            } catch(ParseException ex) {
+                logger.warn("Error parsing start value " + end, ex);
+            }
+        }
+        TimeZone timezone = (tz == null) ? TimeZone.getDefault() : TimeZone.getTimeZone(tz);
         Result onMatch = match == null ? Result.NEUTRAL : Result.valueOf(match);
         Result onMismatch = mismatch == null ? Result.DENY : Result.valueOf(mismatch);
 
-        return new ThresholdFilter(level, onMatch, onMismatch);
+        return new TimeFilter(s, e, timezone, onMatch, onMismatch);
     }
 
 }



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


Mime
View raw message