You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@logging.apache.org by gg...@apache.org on 2012/11/04 17:05:59 UTC

svn commit: r1405577 - in /logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core: ./ filter/

Author: ggregory
Date: Sun Nov  4 16:05:58 2012
New Revision: 1405577

URL: http://svn.apache.org/viewvc?rev=1405577&view=rev
Log:
Refactor Result creation with safe upper case in a new toResult method.

Modified:
    logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/Filter.java
    logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/filter/BurstFilter.java
    logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/filter/DynamicThresholdFilter.java
    logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/filter/MapFilter.java
    logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/filter/MarkerFilter.java
    logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/filter/RegexFilter.java
    logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/filter/StructuredDataFilter.java
    logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/filter/ThreadContextMapFilter.java
    logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/filter/ThresholdFilter.java
    logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/filter/TimeFilter.java

Modified: logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/Filter.java
URL: http://svn.apache.org/viewvc/logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/Filter.java?rev=1405577&r1=1405576&r2=1405577&view=diff
==============================================================================
--- logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/Filter.java (original)
+++ logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/Filter.java Sun Nov  4 16:05:58 2012
@@ -17,6 +17,8 @@
 
 package org.apache.logging.log4j.core;
 
+import java.util.Locale;
+
 import org.apache.logging.log4j.Level;
 import org.apache.logging.log4j.Marker;
 import org.apache.logging.log4j.message.Message;
@@ -46,7 +48,17 @@ public interface Filter {
         /**
          * The event should not be processed.
          */
-        DENY
+        DENY;
+        
+        /**
+         * Returns the Result for the given string.
+         * 
+         * @param name The Result enum name, case-insensitive. If null, returns, null
+         * @return a Result enum value
+         */
+        public static Result toResult(String name) {
+            return Result.valueOf(name.toUpperCase(Locale.ENGLISH));
+        }
     }
 
     /**

Modified: logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/filter/BurstFilter.java
URL: http://svn.apache.org/viewvc/logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/filter/BurstFilter.java?rev=1405577&r1=1405576&r2=1405577&view=diff
==============================================================================
--- logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/filter/BurstFilter.java (original)
+++ logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/filter/BurstFilter.java Sun Nov  4 16:05:58 2012
@@ -224,8 +224,8 @@ public final class BurstFilter extends A
                                            @PluginAttr("maxBurst") String maxBurst,
                                            @PluginAttr("onmatch") String match,
                                            @PluginAttr("onmismatch") String mismatch) {
-        Result onMatch = match == null ? null : Result.valueOf(match.toUpperCase(Locale.ENGLISH));
-        Result onMismatch = mismatch == null ? null : Result.valueOf(mismatch.toUpperCase(Locale.ENGLISH));
+        Result onMatch = match == null ? null : Result.toResult(match);
+        Result onMismatch = mismatch == null ? null : Result.toResult(mismatch);
         Level lvl = Level.toLevel(level, Level.WARN);
         float eventRate = rate == null ? DEFAULT_RATE : Float.parseFloat(rate);
         if (eventRate <= 0) {

Modified: logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/filter/DynamicThresholdFilter.java
URL: http://svn.apache.org/viewvc/logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/filter/DynamicThresholdFilter.java?rev=1405577&r1=1405576&r2=1405577&view=diff
==============================================================================
--- logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/filter/DynamicThresholdFilter.java (original)
+++ logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/filter/DynamicThresholdFilter.java Sun Nov  4 16:05:58 2012
@@ -128,8 +128,8 @@ public final class DynamicThresholdFilte
                                                       @PluginAttr("defaultThreshold") String level,
                                                       @PluginAttr("onmatch") String match,
                                                       @PluginAttr("onmismatch") String mismatch) {
-        Result onMatch = match == null ? null : Result.valueOf(match.toUpperCase(Locale.ENGLISH));
-        Result onMismatch = mismatch == null ? null : Result.valueOf(mismatch.toUpperCase(Locale.ENGLISH));
+        Result onMatch = match == null ? null : Result.toResult(match);
+        Result onMismatch = mismatch == null ? null : Result.toResult(mismatch);
         Map<String, Level> map = new HashMap<String, Level>();
         for (KeyValuePair pair : pairs) {
             map.put(pair.getKey(), Level.toLevel(pair.getValue().toUpperCase(Locale.ENGLISH)));

Modified: logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/filter/MapFilter.java
URL: http://svn.apache.org/viewvc/logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/filter/MapFilter.java?rev=1405577&r1=1405576&r2=1405577&view=diff
==============================================================================
--- logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/filter/MapFilter.java (original)
+++ logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/filter/MapFilter.java Sun Nov  4 16:05:58 2012
@@ -149,8 +149,8 @@ public class MapFilter extends AbstractF
             return null;
         }
         boolean isAnd = oper == null || !oper.equalsIgnoreCase("or");
-        Result onMatch = match == null ? null : Result.valueOf(match.toUpperCase(Locale.ENGLISH));
-        Result onMismatch = mismatch == null ? null : Result.valueOf(mismatch.toUpperCase(Locale.ENGLISH));
+        Result onMatch = match == null ? null : Result.toResult(match);
+        Result onMismatch = mismatch == null ? null : Result.toResult(mismatch);
         return new MapFilter(map, isAnd, onMatch, onMismatch);
     }
 }

Modified: logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/filter/MarkerFilter.java
URL: http://svn.apache.org/viewvc/logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/filter/MarkerFilter.java?rev=1405577&r1=1405576&r2=1405577&view=diff
==============================================================================
--- logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/filter/MarkerFilter.java (original)
+++ logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/filter/MarkerFilter.java Sun Nov  4 16:05:58 2012
@@ -87,9 +87,8 @@ public final class MarkerFilter extends 
             LOGGER.error("A marker must be provided for MarkerFilter");
             return null;
         }
-        Result onMatch = match == null ? null : Result.valueOf(match.toUpperCase(Locale.ENGLISH));
-        Result onMismatch = mismatch == null ? null : Result.valueOf(mismatch.toUpperCase(Locale.ENGLISH));
-
+        Result onMatch = match == null ? null : Result.toResult(match);
+        Result onMismatch = mismatch == null ? null : Result.toResult(mismatch);
         return new MarkerFilter(marker, onMatch, onMismatch);
     }
 

Modified: logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/filter/RegexFilter.java
URL: http://svn.apache.org/viewvc/logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/filter/RegexFilter.java?rev=1405577&r1=1405576&r2=1405577&view=diff
==============================================================================
--- logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/filter/RegexFilter.java (original)
+++ logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/filter/RegexFilter.java Sun Nov  4 16:05:58 2012
@@ -113,8 +113,8 @@ public final class RegexFilter extends A
             LOGGER.error("RegexFilter caught exception compiling pattern: " + regex + " cause: " + ex.getMessage());
             return null;
         }
-        Result onMatch = match == null ? null : Result.valueOf(match.toUpperCase(Locale.ENGLISH));
-        Result onMismatch = mismatch == null ? null : Result.valueOf(mismatch.toUpperCase(Locale.ENGLISH));
+        Result onMatch = match == null ? null : Result.toResult(match);
+        Result onMismatch = mismatch == null ? null : Result.toResult(mismatch);
 
         return new RegexFilter(raw, pattern, onMatch, onMismatch);
     }

Modified: logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/filter/StructuredDataFilter.java
URL: http://svn.apache.org/viewvc/logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/filter/StructuredDataFilter.java?rev=1405577&r1=1405576&r2=1405577&view=diff
==============================================================================
--- logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/filter/StructuredDataFilter.java (original)
+++ logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/filter/StructuredDataFilter.java Sun Nov  4 16:05:58 2012
@@ -133,8 +133,8 @@ public final class StructuredDataFilter 
             return null;
         }
         boolean isAnd = oper == null || !oper.equalsIgnoreCase("or");
-        Result onMatch = match == null ? null : Result.valueOf(match.toUpperCase(Locale.ENGLISH));
-        Result onMismatch = mismatch == null ? null : Result.valueOf(mismatch.toUpperCase(Locale.ENGLISH));
+        Result onMatch = match == null ? null : Result.toResult(match);
+        Result onMismatch = mismatch == null ? null : Result.toResult(mismatch);
         return new StructuredDataFilter(map, isAnd, onMatch, onMismatch);
     }
 }

Modified: logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/filter/ThreadContextMapFilter.java
URL: http://svn.apache.org/viewvc/logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/filter/ThreadContextMapFilter.java?rev=1405577&r1=1405576&r2=1405577&view=diff
==============================================================================
--- logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/filter/ThreadContextMapFilter.java (original)
+++ logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/filter/ThreadContextMapFilter.java Sun Nov  4 16:05:58 2012
@@ -142,8 +142,8 @@ public class ThreadContextMapFilter exte
             return null;
         }
         boolean isAnd = oper == null || !oper.equalsIgnoreCase("or");
-        Result onMatch = match == null ? null : Result.valueOf(match.toUpperCase(Locale.ENGLISH));
-        Result onMismatch = mismatch == null ? null : Result.valueOf(mismatch.toUpperCase(Locale.ENGLISH));
+        Result onMatch = match == null ? null : Result.toResult(match);
+        Result onMismatch = mismatch == null ? null : Result.toResult(mismatch);
         return new ThreadContextMapFilter(map, isAnd, onMatch, onMismatch);
     }
 }

Modified: logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/filter/ThresholdFilter.java
URL: http://svn.apache.org/viewvc/logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/filter/ThresholdFilter.java?rev=1405577&r1=1405576&r2=1405577&view=diff
==============================================================================
--- logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/filter/ThresholdFilter.java (original)
+++ logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/filter/ThresholdFilter.java Sun Nov  4 16:05:58 2012
@@ -86,8 +86,8 @@ public final class ThresholdFilter exten
                                                @PluginAttr("onMatch") String match,
                                                @PluginAttr("onMismatch") String mismatch) {
         Level level = loggerLevel == null ? Level.ERROR : Level.toLevel(loggerLevel.toUpperCase(Locale.ENGLISH));
-        Result onMatch = match == null ? Result.NEUTRAL : Result.valueOf(match.toUpperCase(Locale.ENGLISH));
-        Result onMismatch = mismatch == null ? Result.DENY : Result.valueOf(mismatch.toUpperCase(Locale.ENGLISH));
+        Result onMatch = match == null ? Result.NEUTRAL : Result.toResult(match);
+        Result onMismatch = mismatch == null ? Result.DENY : Result.toResult(mismatch);
 
         return new ThresholdFilter(level, onMatch, onMismatch);
     }

Modified: logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/filter/TimeFilter.java
URL: http://svn.apache.org/viewvc/logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/filter/TimeFilter.java?rev=1405577&r1=1405576&r2=1405577&view=diff
==============================================================================
--- logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/filter/TimeFilter.java (original)
+++ logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/filter/TimeFilter.java Sun Nov  4 16:05:58 2012
@@ -127,8 +127,8 @@ public final class TimeFilter extends Ab
             }
         }
         TimeZone timezone = (tz == null) ? TimeZone.getDefault() : TimeZone.getTimeZone(tz);
-        Result onMatch = match == null ? Result.NEUTRAL : Result.valueOf(match.toUpperCase(Locale.ENGLISH));
-        Result onMismatch = mismatch == null ? Result.DENY : Result.valueOf(mismatch.toUpperCase(Locale.ENGLISH));
+        Result onMatch = match == null ? Result.NEUTRAL : Result.toResult(match);
+        Result onMismatch = mismatch == null ? Result.DENY : Result.toResult(mismatch);
 
         return new TimeFilter(s, e, timezone, onMatch, onMismatch);
     }