logging-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ggreg...@apache.org
Subject svn commit: r1405578 - in /logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core: ./ filter/
Date Sun, 04 Nov 2012 16:15:33 GMT
Author: ggregory
Date: Sun Nov  4 16:15:32 2012
New Revision: 1405578

URL: http://svn.apache.org/viewvc?rev=1405578&view=rev
Log:
Refactor Result creation with safe upper case in a new toResult method with a default value.
This removes a lot of duplicate code.

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/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=1405578&r1=1405577&r2=1405578&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:15:32 2012
@@ -54,12 +54,23 @@ public interface Filter {
          * Returns the Result for the given string.
          * 
          * @param name The Result enum name, case-insensitive. If null, returns, null
-         * @return a Result enum value
+         * @return a Result enum value or null if name is null
          */
         public static Result toResult(String name) {
-            return Result.valueOf(name.toUpperCase(Locale.ENGLISH));
+            return toResult(name, null);
         }
-    }
+
+        /**
+         * Returns the Result for the given string.
+         * 
+         * @param name The Result enum name, case-insensitive. If null, returns, defaultResult
+         * @param defaultResult the Result to return if name is null
+         * @return a Result enum value or null if name is null
+         */
+        public static Result toResult(String name, Result defaultResult) {
+            return name == null ? defaultResult : Result.valueOf(name.toUpperCase(Locale.ENGLISH));
+        }
+}
 
     /**
      * Returns the result that should be returned when the filter does not match the event.

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=1405578&r1=1405577&r2=1405578&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:15:32 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.toResult(match);
-        Result onMismatch = mismatch == null ? null : Result.toResult(mismatch);
+        Result onMatch = Result.toResult(match);
+        Result onMismatch = 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/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=1405578&r1=1405577&r2=1405578&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:15:32 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.toResult(match);
-        Result onMismatch = mismatch == null ? null : Result.toResult(mismatch);
+        Result onMatch = Result.toResult(match);
+        Result onMismatch = 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=1405578&r1=1405577&r2=1405578&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:15:32 2012
@@ -87,8 +87,8 @@ public final class MarkerFilter extends 
             LOGGER.error("A marker must be provided for MarkerFilter");
             return null;
         }
-        Result onMatch = match == null ? null : Result.toResult(match);
-        Result onMismatch = mismatch == null ? null : Result.toResult(mismatch);
+        Result onMatch = Result.toResult(match);
+        Result onMismatch = 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=1405578&r1=1405577&r2=1405578&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:15:32 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.toResult(match);
-        Result onMismatch = mismatch == null ? null : Result.toResult(mismatch);
+        Result onMatch = Result.toResult(match);
+        Result onMismatch = 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=1405578&r1=1405577&r2=1405578&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:15:32 2012
@@ -133,8 +133,8 @@ public final class StructuredDataFilter 
             return null;
         }
         boolean isAnd = oper == null || !oper.equalsIgnoreCase("or");
-        Result onMatch = match == null ? null : Result.toResult(match);
-        Result onMismatch = mismatch == null ? null : Result.toResult(mismatch);
+        Result onMatch = Result.toResult(match);
+        Result onMismatch = 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=1405578&r1=1405577&r2=1405578&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:15:32 2012
@@ -142,8 +142,8 @@ public class ThreadContextMapFilter exte
             return null;
         }
         boolean isAnd = oper == null || !oper.equalsIgnoreCase("or");
-        Result onMatch = match == null ? null : Result.toResult(match);
-        Result onMismatch = mismatch == null ? null : Result.toResult(mismatch);
+        Result onMatch = Result.toResult(match);
+        Result onMismatch = 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=1405578&r1=1405577&r2=1405578&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:15:32 2012
@@ -86,9 +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.toResult(match);
-        Result onMismatch = mismatch == null ? Result.DENY : Result.toResult(mismatch);
-
+        Result onMatch = Result.toResult(match, Result.NEUTRAL);
+        Result onMismatch = Result.toResult(mismatch, Result.DENY);
         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=1405578&r1=1405577&r2=1405578&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:15:32 2012
@@ -127,9 +127,8 @@ public final class TimeFilter extends Ab
             }
         }
         TimeZone timezone = (tz == null) ? TimeZone.getDefault() : TimeZone.getTimeZone(tz);
-        Result onMatch = match == null ? Result.NEUTRAL : Result.toResult(match);
-        Result onMismatch = mismatch == null ? Result.DENY : Result.toResult(mismatch);
-
+        Result onMatch = Result.toResult(match, Result.NEUTRAL);
+        Result onMismatch = Result.toResult(mismatch, Result.DENY);
         return new TimeFilter(s, e, timezone, onMatch, onMismatch);
     }
 



Mime
View raw message