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 19:54:17 UTC

svn commit: r1405606 - in /logging/log4j/log4j2/trunk: api/src/main/java/org/apache/logging/log4j/ api/src/main/java/org/apache/logging/log4j/message/ api/src/main/java/org/apache/logging/log4j/util/ core/src/main/java/org/apache/logging/log4j/core/ co...

Author: ggregory
Date: Sun Nov  4 18:54:16 2012
New Revision: 1405606

URL: http://svn.apache.org/viewvc?rev=1405606&view=rev
Log:
Refactor code pattern that converts a String to upper case and then to a Level enum value in one place. The English locale is used to convert to upper case to avoid issues when running on the Turkish locale. Since the Log4J enums are in English, we can safely use the English locale.

Added:
    logging/log4j/log4j2/trunk/api/src/main/java/org/apache/logging/log4j/util/EnglishEnums.java   (with props)
Modified:
    logging/log4j/log4j2/trunk/api/src/main/java/org/apache/logging/log4j/Level.java
    logging/log4j/log4j2/trunk/api/src/main/java/org/apache/logging/log4j/message/MapMessage.java
    logging/log4j/log4j2/trunk/api/src/main/java/org/apache/logging/log4j/message/StructuredDataMessage.java
    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/appender/SocketAppender.java
    logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/config/AppenderRef.java
    logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/config/JSONConfiguration.java
    logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/config/LoggerConfig.java
    logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/config/XMLConfiguration.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/ThresholdFilter.java
    logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/layout/RFC5424Layout.java
    logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/layout/SyslogLayout.java
    logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/net/Facility.java
    logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/pattern/LevelPatternConverter.java

Modified: logging/log4j/log4j2/trunk/api/src/main/java/org/apache/logging/log4j/Level.java
URL: http://svn.apache.org/viewvc/logging/log4j/log4j2/trunk/api/src/main/java/org/apache/logging/log4j/Level.java?rev=1405606&r1=1405605&r2=1405606&view=diff
==============================================================================
--- logging/log4j/log4j2/trunk/api/src/main/java/org/apache/logging/log4j/Level.java (original)
+++ logging/log4j/log4j2/trunk/api/src/main/java/org/apache/logging/log4j/Level.java Sun Nov  4 18:54:16 2012
@@ -16,6 +16,8 @@
  */
 package org.apache.logging.log4j;
 
+import java.util.Locale;
+
 /**
  * Levels used for identifying the severity of an event. Levels are organized from most specific to least:
  * <ul>
@@ -89,16 +91,17 @@ public enum Level {
      * conversion fails, then this method returns the value of
      * <code>defaultLevel</code>.
      *
-     * @param sArg The name of the desired Level.
+     * @param name The name of the desired Level.
      * @param defaultLevel The Level to use if the String is invalid.
      * @return The Level associated with the String.
      */
-    public static Level toLevel(String sArg, Level defaultLevel) {
-        if (sArg == null) {
+    public static Level toLevel(final String name, final Level defaultLevel) {
+        if (name == null) {
             return defaultLevel;
         }
+        final String cleanLevel = name.toUpperCase(Locale.ENGLISH);
         for (Level level : values()) {
-            if (level.name().equals(sArg)) {
+            if (level.name().equals(cleanLevel)) {
                 return level;
             }
         }

Modified: logging/log4j/log4j2/trunk/api/src/main/java/org/apache/logging/log4j/message/MapMessage.java
URL: http://svn.apache.org/viewvc/logging/log4j/log4j2/trunk/api/src/main/java/org/apache/logging/log4j/message/MapMessage.java?rev=1405606&r1=1405605&r2=1405606&view=diff
==============================================================================
--- logging/log4j/log4j2/trunk/api/src/main/java/org/apache/logging/log4j/message/MapMessage.java (original)
+++ logging/log4j/log4j2/trunk/api/src/main/java/org/apache/logging/log4j/message/MapMessage.java Sun Nov  4 18:54:16 2012
@@ -23,6 +23,8 @@ import java.util.Map;
 import java.util.SortedMap;
 import java.util.TreeMap;
 
+import org.apache.logging.log4j.util.EnglishEnums;
+
 /**
  * Represents a Message that consists of a Map.
  */
@@ -153,7 +155,7 @@ public class MapMessage implements Multi
 
     public String asString(String format) {
         try {
-            return asString(MapFormat.valueOf(format.toUpperCase(Locale.ENGLISH)));
+            return asString(EnglishEnums.valueOf(MapFormat.class, format));
         } catch (IllegalArgumentException ex) {
             return asString();
         }

Modified: logging/log4j/log4j2/trunk/api/src/main/java/org/apache/logging/log4j/message/StructuredDataMessage.java
URL: http://svn.apache.org/viewvc/logging/log4j/log4j2/trunk/api/src/main/java/org/apache/logging/log4j/message/StructuredDataMessage.java?rev=1405606&r1=1405605&r2=1405606&view=diff
==============================================================================
--- logging/log4j/log4j2/trunk/api/src/main/java/org/apache/logging/log4j/message/StructuredDataMessage.java (original)
+++ logging/log4j/log4j2/trunk/api/src/main/java/org/apache/logging/log4j/message/StructuredDataMessage.java Sun Nov  4 18:54:16 2012
@@ -20,6 +20,9 @@ import java.io.Serializable;
 import java.util.Locale;
 import java.util.Map;
 
+import org.apache.logging.log4j.message.MapMessage.MapFormat;
+import org.apache.logging.log4j.util.EnglishEnums;
+
 /**
  * Represents a Message that conforms to RFC 5424 (http://tools.ietf.org/html/rfc5424).
  */
@@ -213,7 +216,7 @@ public class StructuredDataMessage exten
     @Override
     public String asString(String format) {
         try {
-            return asString(Format.valueOf(format.toUpperCase(Locale.ENGLISH)), null);
+            return asString(EnglishEnums.valueOf(Format.class, format), null);
         } catch (IllegalArgumentException ex) {
             return asString();
         }

Added: logging/log4j/log4j2/trunk/api/src/main/java/org/apache/logging/log4j/util/EnglishEnums.java
URL: http://svn.apache.org/viewvc/logging/log4j/log4j2/trunk/api/src/main/java/org/apache/logging/log4j/util/EnglishEnums.java?rev=1405606&view=auto
==============================================================================
--- logging/log4j/log4j2/trunk/api/src/main/java/org/apache/logging/log4j/util/EnglishEnums.java (added)
+++ logging/log4j/log4j2/trunk/api/src/main/java/org/apache/logging/log4j/util/EnglishEnums.java Sun Nov  4 18:54:16 2012
@@ -0,0 +1,46 @@
+package org.apache.logging.log4j.util;
+
+import java.util.Locale;
+
+/**
+ * Helps convert English Strings to English Enum values.
+ * <p>
+ * Enum name arguments are converted internally to upper case with the {@linkplain Locale#ENGLISH ENGLISH} locale to
+ * avoid problems on the Turkish locale. Do not use with Turkish enum values.
+ * </p>
+ */
+public class EnglishEnums {
+
+    /**
+     * Returns the Result for the given string.
+     * <p>
+     * The {@code name} is converted internally to upper case with the {@linkplain Locale#ENGLISH ENGLISH} locale to
+     * avoid problems on the Turkish locale. Do not use with Turkish enum values.
+     * </p>
+     * 
+     * @param name
+     *            The enum name, case-insensitive. If null, returns {@code defaultValue}
+     * @return an enum value or null if {@code name} is null
+     */
+    public static <T extends Enum<T>> T valueOf(Class<T> enumType, String name) {
+        return valueOf(enumType, name, null);
+    }
+
+    /**
+     * Returns an enum value for the given string.
+     * <p>
+     * The {@code name} is converted internally to upper case with the {@linkplain Locale#ENGLISH ENGLISH} locale to
+     * avoid problems on the Turkish locale. Do not use with Turkish enum values.
+     * </p>
+     * 
+     * @param name
+     *            The enum name, case-insensitive. If null, returns {@code defaultValue}
+     * @param defaultValue
+     *            the enum value to return if {@code name} is null
+     * @return an enum value or {@code defaultValue} if {@code name} is null
+     */
+    public static <T extends Enum<T>> T valueOf(Class<T> enumType, String name, T defaultValue) {
+        return name == null ? defaultValue : Enum.valueOf(enumType, name.toUpperCase(Locale.ENGLISH));
+    }
+
+}

Propchange: logging/log4j/log4j2/trunk/api/src/main/java/org/apache/logging/log4j/util/EnglishEnums.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: logging/log4j/log4j2/trunk/api/src/main/java/org/apache/logging/log4j/util/EnglishEnums.java
------------------------------------------------------------------------------
    svn:keywords = Id

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=1405606&r1=1405605&r2=1405606&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 18:54:16 2012
@@ -21,7 +21,9 @@ import java.util.Locale;
 
 import org.apache.logging.log4j.Level;
 import org.apache.logging.log4j.Marker;
+import org.apache.logging.log4j.core.net.Protocol;
 import org.apache.logging.log4j.message.Message;
+import org.apache.logging.log4j.util.EnglishEnums;
 
 /**
  * Interface that must be implemented to allow custom event filtering. It is highly recommended that
@@ -68,7 +70,7 @@ public interface Filter {
          * @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));
+            return EnglishEnums.valueOf(Result.class, name, defaultResult);
         }
 }
 

Modified: logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/appender/SocketAppender.java
URL: http://svn.apache.org/viewvc/logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/appender/SocketAppender.java?rev=1405606&r1=1405605&r2=1405606&view=diff
==============================================================================
--- logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/appender/SocketAppender.java (original)
+++ logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/appender/SocketAppender.java Sun Nov  4 18:54:16 2012
@@ -27,8 +27,10 @@ import org.apache.logging.log4j.core.con
 import org.apache.logging.log4j.core.layout.SerializedLayout;
 import org.apache.logging.log4j.core.net.AbstractSocketManager;
 import org.apache.logging.log4j.core.net.DatagramSocketManager;
+import org.apache.logging.log4j.core.net.Facility;
 import org.apache.logging.log4j.core.net.Protocol;
 import org.apache.logging.log4j.core.net.TCPSocketManager;
+import org.apache.logging.log4j.util.EnglishEnums;
 
 /**
  * An Appender that delivers events over socket connections. Supports both TCP and UDP.
@@ -89,7 +91,7 @@ public class SocketAppender extends Abst
     }
 
     protected static AbstractSocketManager createSocketManager(String protocol, String host, int port, int delay) {
-        Protocol p = Protocol.valueOf(protocol.toUpperCase(Locale.ENGLISH));
+        Protocol p = EnglishEnums.valueOf(Protocol.class, protocol);
         switch (p) {
             case TCP:
                 return TCPSocketManager.getSocketManager(host, port, delay);

Modified: logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/config/AppenderRef.java
URL: http://svn.apache.org/viewvc/logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/config/AppenderRef.java?rev=1405606&r1=1405605&r2=1405606&view=diff
==============================================================================
--- logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/config/AppenderRef.java (original)
+++ logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/config/AppenderRef.java Sun Nov  4 18:54:16 2012
@@ -59,13 +59,13 @@ public final class AppenderRef {
     /**
      * Create an Appender reference.
      * @param ref The name of the Appender.
-     * @param level The Level to filter against.
+     * @param levelName The Level to filter against.
      * @param filter The filter(s) to use.
      * @return The name of the Appender.
      */
     @PluginFactory
     public static AppenderRef createAppenderRef(@PluginAttr("ref") String ref,
-                                                @PluginAttr("level") String level,
+                                                @PluginAttr("level") String levelName,
                                                 @PluginElement("filters") Filter filter) {
 
         if (ref == null) {
@@ -74,10 +74,10 @@ public final class AppenderRef {
         }
         Level l = null;
 
-        if (level != null) {
-            l = Level.toLevel(level.toUpperCase(Locale.ENGLISH), null);
+        if (levelName != null) {
+            l = Level.toLevel(levelName, null);
             if (l == null) {
-                LOGGER.error("Invalid level " + level + " on Appender reference " + ref);
+                LOGGER.error("Invalid level " + levelName + " on Appender reference " + ref);
             }
         }
 

Modified: logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/config/JSONConfiguration.java
URL: http://svn.apache.org/viewvc/logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/config/JSONConfiguration.java?rev=1405606&r1=1405605&r2=1405606&view=diff
==============================================================================
--- logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/config/JSONConfiguration.java (original)
+++ logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/config/JSONConfiguration.java Sun Nov  4 18:54:16 2012
@@ -83,7 +83,7 @@ public class JSONConfiguration extends B
             PrintStream stream = System.out;
             for (Map.Entry<String, String> entry : rootNode.getAttributes().entrySet()) {
                 if ("status".equalsIgnoreCase(entry.getKey())) {
-                    status = Level.toLevel(getSubst().replace(entry.getValue()).toUpperCase(Locale.ENGLISH), null);
+                    status = Level.toLevel(getSubst().replace(entry.getValue()), null);
                     if (status == null) {
                         status = Level.ERROR;
                         messages.add("Invalid status specified: " + entry.getValue() + ". Defaulting to ERROR");

Modified: logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/config/LoggerConfig.java
URL: http://svn.apache.org/viewvc/logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/config/LoggerConfig.java?rev=1405606&r1=1405605&r2=1405606&view=diff
==============================================================================
--- logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/config/LoggerConfig.java (original)
+++ logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/config/LoggerConfig.java Sun Nov  4 18:54:16 2012
@@ -359,7 +359,7 @@ public class LoggerConfig extends Abstra
     /**
      * Factory method to create a LoggerConfig.
      * @param additivity True if additive, false otherwise.
-     * @param loggerLevel The Level to be associated with the Logger.
+     * @param levelName The Level to be associated with the Logger.
      * @param loggerName The name of the Logger.
      * @param refs An array of Appender names.
      * @param filter A Filter.
@@ -367,7 +367,7 @@ public class LoggerConfig extends Abstra
      */
     @PluginFactory
     public static LoggerConfig createLogger(@PluginAttr("additivity") String additivity,
-                                            @PluginAttr("level") String loggerLevel,
+                                            @PluginAttr("level") String levelName,
                                             @PluginAttr("name") String loggerName,
                                             @PluginElement("appender-ref") AppenderRef[] refs,
                                             @PluginElement("properties") Property[] properties,
@@ -381,9 +381,9 @@ public class LoggerConfig extends Abstra
         List<AppenderRef> appenderRefs = Arrays.asList(refs);
         Level level;
         try {
-            level = loggerLevel == null ? Level.ERROR : Level.valueOf(loggerLevel.toUpperCase(Locale.ENGLISH));
+            level = Level.toLevel(levelName, Level.ERROR);
         } catch (Exception ex) {
-            LOGGER.error("Invalid Log level specified: {}. Defaulting to Error", loggerLevel);
+            LOGGER.error("Invalid Log level specified: {}. Defaulting to Error", levelName);
             level = Level.ERROR;
         }
         String name = loggerName.equals("root") ? "" : loggerName;
@@ -400,7 +400,7 @@ public class LoggerConfig extends Abstra
 
         @PluginFactory
         public static LoggerConfig createLogger(@PluginAttr("additivity") String additivity,
-                                            @PluginAttr("level") String loggerLevel,
+                                            @PluginAttr("level") String levelName,
                                             @PluginElement("appender-ref") AppenderRef[] refs,
                                             @PluginElement("properties") Property[] properties,
                                             @PluginConfiguration Configuration config,
@@ -408,9 +408,9 @@ public class LoggerConfig extends Abstra
             List<AppenderRef> appenderRefs = Arrays.asList(refs);
             Level level;
             try {
-                level = loggerLevel == null ? Level.ERROR : Level.valueOf(loggerLevel.toUpperCase(Locale.ENGLISH));
+                level = Level.toLevel(levelName, Level.ERROR);
             } catch (Exception ex) {
-                LOGGER.error("Invalid Log level specified: {}. Defaulting to Error", loggerLevel);
+                LOGGER.error("Invalid Log level specified: {}. Defaulting to Error", levelName);
                 level = Level.ERROR;
             }
             boolean additive = additivity == null ? true : Boolean.parseBoolean(additivity);

Modified: logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/config/XMLConfiguration.java
URL: http://svn.apache.org/viewvc/logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/config/XMLConfiguration.java?rev=1405606&r1=1405605&r2=1405606&view=diff
==============================================================================
--- logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/config/XMLConfiguration.java (original)
+++ logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/config/XMLConfiguration.java Sun Nov  4 18:54:16 2012
@@ -103,7 +103,7 @@ public class XMLConfiguration extends Ba
 
             for (Map.Entry<String, String> entry : attrs.entrySet()) {
                 if ("status".equalsIgnoreCase(entry.getKey())) {
-                    status = Level.toLevel(getSubst().replace(entry.getValue()).toUpperCase(Locale.ENGLISH), null);
+                    status = Level.toLevel(getSubst().replace(entry.getValue()), null);
                     if (status == null) {
                         status = Level.ERROR;
                         messages.add("Invalid status specified: " + entry.getValue() + ". Defaulting to ERROR");

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=1405606&r1=1405605&r2=1405606&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 18:54:16 2012
@@ -132,7 +132,7 @@ public final class DynamicThresholdFilte
         Result onMismatch = 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)));
+            map.put(pair.getKey(), Level.toLevel(pair.getValue()));
         }
         Level l = Level.toLevel(level, Level.ERROR);
         return new DynamicThresholdFilter(key, map, l, 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=1405606&r1=1405605&r2=1405606&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 18:54:16 2012
@@ -76,16 +76,16 @@ public final class ThresholdFilter exten
 
     /**
      * Create a ThresholdFilter.
-     * @param loggerLevel The log Level.
+     * @param levelName The log Level.
      * @param match The action to take on a match.
      * @param mismatch The action to take on a mismatch.
      * @return The created ThresholdFilter.
      */
     @PluginFactory
-    public static ThresholdFilter createFilter(@PluginAttr("level") String loggerLevel,
+    public static ThresholdFilter createFilter(@PluginAttr("level") String levelName,
                                                @PluginAttr("onMatch") String match,
                                                @PluginAttr("onMismatch") String mismatch) {
-        Level level = loggerLevel == null ? Level.ERROR : Level.toLevel(loggerLevel.toUpperCase(Locale.ENGLISH));
+        Level level = Level.toLevel(levelName, Level.ERROR);
         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/layout/RFC5424Layout.java
URL: http://svn.apache.org/viewvc/logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/layout/RFC5424Layout.java?rev=1405606&r1=1405605&r2=1405606&view=diff
==============================================================================
--- logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/layout/RFC5424Layout.java (original)
+++ logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/layout/RFC5424Layout.java Sun Nov  4 18:54:16 2012
@@ -28,6 +28,7 @@ import org.apache.logging.log4j.core.net
 import org.apache.logging.log4j.message.Message;
 import org.apache.logging.log4j.message.StructuredDataId;
 import org.apache.logging.log4j.message.StructuredDataMessage;
+import org.apache.logging.log4j.util.EnglishEnums;
 
 import java.net.InetAddress;
 import java.net.NetworkInterface;
@@ -469,7 +470,7 @@ public final class RFC5424Layout extends
             LOGGER.error("mdcIncludes and mdcExcludes are mutually exclusive. Includes wil be ignored");
             includes = null;
         }
-        Facility f = facility != null ? Facility.valueOf(facility.toUpperCase(Locale.ENGLISH)) : Facility.LOCAL0;
+        Facility f = Facility.toFacility(facility, Facility.LOCAL0);
         int enterpriseNumber = ein == null ? DEFAULT_ENTERPRISE_NUMBER : Integer.parseInt(ein);
         boolean isMdc = includeMDC == null ? true : Boolean.valueOf(includeMDC);
         boolean includeNewLine = includeNL == null ? false : Boolean.valueOf(includeNL);

Modified: logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/layout/SyslogLayout.java
URL: http://svn.apache.org/viewvc/logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/layout/SyslogLayout.java?rev=1405606&r1=1405605&r2=1405606&view=diff
==============================================================================
--- logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/layout/SyslogLayout.java (original)
+++ logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/layout/SyslogLayout.java Sun Nov  4 18:54:16 2012
@@ -22,6 +22,7 @@ import org.apache.logging.log4j.core.con
 import org.apache.logging.log4j.core.config.plugins.PluginFactory;
 import org.apache.logging.log4j.core.net.Facility;
 import org.apache.logging.log4j.core.net.Priority;
+import org.apache.logging.log4j.util.EnglishEnums;
 
 import java.net.InetAddress;
 import java.net.UnknownHostException;
@@ -126,7 +127,7 @@ public class SyslogLayout extends Abstra
             }
         }
         boolean includeNewLine = includeNL == null ? false : Boolean.valueOf(includeNL);
-        Facility f = facility != null ? Facility.valueOf(facility.toUpperCase(Locale.ENGLISH)) : Facility.LOCAL0;
+        Facility f = Facility.toFacility(facility, Facility.LOCAL0);
         return new SyslogLayout(f, includeNewLine, c);
     }
 }

Modified: logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/net/Facility.java
URL: http://svn.apache.org/viewvc/logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/net/Facility.java?rev=1405606&r1=1405605&r2=1405606&view=diff
==============================================================================
--- logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/net/Facility.java (original)
+++ logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/net/Facility.java Sun Nov  4 18:54:16 2012
@@ -16,6 +16,8 @@
  */
 package org.apache.logging.log4j.core.net;
 
+import org.apache.logging.log4j.util.EnglishEnums;
+
 /**
  *  The facility codes used by the Syslog system.
  *
@@ -97,6 +99,27 @@ public enum Facility {
     /** Local use 7. */
     LOCAL7(23);
 
+    /**
+     * Returns the Facility for the given string.
+     * 
+     * @param name The Facility enum name, case-insensitive. If null, returns, null
+     * @return a Facility enum value or null if name is null
+     */
+    public static Facility toFacility(String name) {
+        return toFacility(name, null);
+    }
+
+    /**
+     * Returns the Facility for the given string.
+     * 
+     * @param name The Facility enum name, case-insensitive. If null, returns, defaultFacility
+     * @param defaultFacility the Facility to return if name is null
+     * @return a Facility enum value or null if name is null
+     */
+    public static Facility toFacility(String name, Facility defaultFacility) {
+        return EnglishEnums.valueOf(Facility.class, name, defaultFacility);
+    }
+
     private final int code;
 
     private Facility(int code) {

Modified: logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/pattern/LevelPatternConverter.java
URL: http://svn.apache.org/viewvc/logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/pattern/LevelPatternConverter.java?rev=1405606&r1=1405605&r2=1405606&view=diff
==============================================================================
--- logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/pattern/LevelPatternConverter.java (original)
+++ logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/pattern/LevelPatternConverter.java Sun Nov  4 18:54:16 2012
@@ -64,7 +64,7 @@ public final class LevelPatternConverter
                 LOGGER.error("Invalid option {}", def);
                 continue;
             }
-            Level level = Level.toLevel(pair[0].trim().toUpperCase(Locale.ENGLISH), null);
+            Level level = Level.toLevel(pair[0].trim(), null);
             if (level == null) {
                 LOGGER.error("Invalid Level {}", pair[0].trim());
             }