You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@logging.apache.org by ma...@apache.org on 2014/09/08 20:50:35 UTC

[1/2] git commit: Rename Levels to LevelTranslator.

Repository: logging-log4j2
Updated Branches:
  refs/heads/master ed4ac5310 -> 545cdca8e


Rename Levels to LevelTranslator.


Project: http://git-wip-us.apache.org/repos/asf/logging-log4j2/repo
Commit: http://git-wip-us.apache.org/repos/asf/logging-log4j2/commit/4cb8745a
Tree: http://git-wip-us.apache.org/repos/asf/logging-log4j2/tree/4cb8745a
Diff: http://git-wip-us.apache.org/repos/asf/logging-log4j2/diff/4cb8745a

Branch: refs/heads/master
Commit: 4cb8745a12b860696961412547134f0772e6d9f2
Parents: ed4ac53
Author: Matt Sicker <ma...@apache.org>
Authored: Mon Sep 8 13:30:10 2014 -0500
Committer: Matt Sicker <ma...@apache.org>
Committed: Mon Sep 8 13:30:10 2014 -0500

----------------------------------------------------------------------
 .../org/apache/logging/log4j/jul/ApiLogger.java |   7 +-
 .../apache/logging/log4j/jul/CoreLogger.java    |   3 +-
 .../logging/log4j/jul/LevelTranslator.java      | 111 +++++++++++++++++++
 .../org/apache/logging/log4j/jul/Levels.java    | 111 -------------------
 .../logging/log4j/jul/LevelTranslatorTest.java  |  66 +++++++++++
 .../apache/logging/log4j/jul/LevelsTest.java    |  49 --------
 6 files changed, 183 insertions(+), 164 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/4cb8745a/log4j-jul/src/main/java/org/apache/logging/log4j/jul/ApiLogger.java
----------------------------------------------------------------------
diff --git a/log4j-jul/src/main/java/org/apache/logging/log4j/jul/ApiLogger.java b/log4j-jul/src/main/java/org/apache/logging/log4j/jul/ApiLogger.java
index b9cacab..db47a36 100644
--- a/log4j-jul/src/main/java/org/apache/logging/log4j/jul/ApiLogger.java
+++ b/log4j-jul/src/main/java/org/apache/logging/log4j/jul/ApiLogger.java
@@ -14,6 +14,7 @@
  * See the license for the specific language governing permissions and
  * limitations under the license.
  */
+
 package org.apache.logging.log4j.jul;
 
 import java.util.logging.Filter;
@@ -62,7 +63,7 @@ public class ApiLogger extends Logger {
 
     ApiLogger(final ExtendedLogger logger) {
         super(logger.getName(), null);
-        super.setLevel(Levels.toJavaLevel(logger.getLevel()));
+        super.setLevel(LevelTranslator.toJavaLevel(logger.getLevel()));
         this.logger = logger;
     }
 
@@ -74,7 +75,7 @@ public class ApiLogger extends Logger {
         ThreadContext.put(THREAD_ID, Integer.toString(record.getThreadID()));
         ThreadContext.put(SEQUENCE_NUMBER, Long.toString(record.getSequenceNumber()));
         ThreadContext.put(LEVEL, record.getLevel().getName());
-        final org.apache.logging.log4j.Level level = Levels.toLevel(record.getLevel());
+        final org.apache.logging.log4j.Level level = LevelTranslator.toLevel(record.getLevel());
         final Message message = logger.getMessageFactory().newMessage(record.getMessage(), record.getParameters());
         final Throwable thrown = record.getThrown();
         logger.logIfEnabled(FQCN, level, null, message, thrown);
@@ -91,7 +92,7 @@ public class ApiLogger extends Logger {
 
     @Override
     public boolean isLoggable(final Level level) {
-        return logger.isEnabled(Levels.toLevel(level));
+        return logger.isEnabled(LevelTranslator.toLevel(level));
     }
 
     @Override

http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/4cb8745a/log4j-jul/src/main/java/org/apache/logging/log4j/jul/CoreLogger.java
----------------------------------------------------------------------
diff --git a/log4j-jul/src/main/java/org/apache/logging/log4j/jul/CoreLogger.java b/log4j-jul/src/main/java/org/apache/logging/log4j/jul/CoreLogger.java
index 9887406..eaf7a44 100644
--- a/log4j-jul/src/main/java/org/apache/logging/log4j/jul/CoreLogger.java
+++ b/log4j-jul/src/main/java/org/apache/logging/log4j/jul/CoreLogger.java
@@ -14,6 +14,7 @@
  * See the license for the specific language governing permissions and
  * limitations under the license.
  */
+
 package org.apache.logging.log4j.jul;
 
 import java.util.logging.Level;
@@ -43,7 +44,7 @@ public class CoreLogger extends ApiLogger {
 
     @Override
     public void setLevel(final Level level) throws SecurityException {
-        logger.setLevel(Levels.toLevel(level));
+        logger.setLevel(LevelTranslator.toLevel(level));
         super.doSetLevel(level);
     }
 

http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/4cb8745a/log4j-jul/src/main/java/org/apache/logging/log4j/jul/LevelTranslator.java
----------------------------------------------------------------------
diff --git a/log4j-jul/src/main/java/org/apache/logging/log4j/jul/LevelTranslator.java b/log4j-jul/src/main/java/org/apache/logging/log4j/jul/LevelTranslator.java
new file mode 100644
index 0000000..023be11
--- /dev/null
+++ b/log4j-jul/src/main/java/org/apache/logging/log4j/jul/LevelTranslator.java
@@ -0,0 +1,111 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache license, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the license for the specific language governing permissions and
+ * limitations under the license.
+ */
+
+package org.apache.logging.log4j.jul;
+
+import org.apache.logging.log4j.Level;
+
+/**
+ * Utility class to convert between JDK Levels and Log4j 2 Levels.
+ *
+ * @since 2.1
+ */
+public final class LevelTranslator {
+
+    private static final int JDK_OFF = java.util.logging.Level.OFF.intValue();          // OFF
+    private static final int JDK_SEVERE = java.util.logging.Level.SEVERE.intValue();    // ERROR
+    private static final int JDK_WARNING = java.util.logging.Level.WARNING.intValue();  // WARN
+    private static final int JDK_INFO = java.util.logging.Level.INFO.intValue();        // INFO
+    private static final int JDK_CONFIG = java.util.logging.Level.CONFIG.intValue();    // INFO
+    private static final int JDK_FINE = java.util.logging.Level.FINE.intValue();        // DEBUG
+    private static final int JDK_FINER = java.util.logging.Level.FINER.intValue();      // DEBUG
+    private static final int JDK_FINEST = java.util.logging.Level.FINEST.intValue();    // TRACE
+    private static final int JDK_ALL = java.util.logging.Level.ALL.intValue();          // ALL
+
+    /**
+     * Converts a JDK logging Level to a Log4j logging Level.
+     *
+     * @param level JDK Level to convert.
+     * @return converted Level.
+     */
+    public static Level toLevel(final java.util.logging.Level level) {
+        final int value = level.intValue();
+        if (value == JDK_OFF) { // Integer.MAX_VALUE
+            return Level.OFF;
+        }
+        if (value == JDK_ALL) { // Integer.MIN_VALUE
+            return Level.ALL;
+        }
+        if (value <= JDK_FINEST) { // up to 300
+            return Level.TRACE;
+        }
+        if (value <= JDK_FINER) { // 301 to 400
+            return Level.DEBUG;
+        }
+        if (value <= JDK_FINE) { // 401 to 500
+            return Level.DEBUG;
+        }
+        if (value <= JDK_CONFIG) { // 501 to 700
+            return Level.INFO;
+        }
+        if (value <= JDK_INFO) { // 701 to 800
+            return Level.INFO;
+        }
+        if (value <= JDK_WARNING) { // 801 to 900
+            return Level.WARN;
+        }
+        if (value <= JDK_SEVERE) { // 901 to 1000
+            return Level.ERROR;
+        }
+        // 1001+
+        return Level.FATAL;
+    }
+
+    /**
+     * Converts a Log4j logging Level to a JDK logging Level.
+     *
+     * @param level Log4j Level to convert.
+     * @return converted Level.
+     */
+    public static java.util.logging.Level toJavaLevel(final Level level) {
+        if (level == Level.OFF) {
+            return java.util.logging.Level.OFF;
+        }
+        if (level == Level.TRACE) {
+            return java.util.logging.Level.FINEST;
+        }
+        if (level == Level.DEBUG) {
+            return java.util.logging.Level.FINE;
+        }
+        if (level == Level.INFO) {
+            return java.util.logging.Level.INFO;
+        }
+        if (level == Level.WARN) {
+            return java.util.logging.Level.WARNING;
+        }
+        if (level == Level.ERROR || level == Level.FATAL) {
+            return java.util.logging.Level.SEVERE;
+        }
+        if (level == Level.ALL) {
+            return java.util.logging.Level.ALL;
+        }
+        return java.util.logging.Level.parse(level.name());
+    }
+
+    private LevelTranslator() {
+    }
+}

http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/4cb8745a/log4j-jul/src/main/java/org/apache/logging/log4j/jul/Levels.java
----------------------------------------------------------------------
diff --git a/log4j-jul/src/main/java/org/apache/logging/log4j/jul/Levels.java b/log4j-jul/src/main/java/org/apache/logging/log4j/jul/Levels.java
deleted file mode 100644
index e8ca05e..0000000
--- a/log4j-jul/src/main/java/org/apache/logging/log4j/jul/Levels.java
+++ /dev/null
@@ -1,111 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.logging.log4j.jul;
-
-import org.apache.logging.log4j.Level;
-
-/**
- * Utility class to convert between JDK Levels and Log4j 2 Levels.
- *
- * @since 2.1
- */
-public final class Levels {
-
-    private static final int JDK_OFF = java.util.logging.Level.OFF.intValue();          // OFF
-    private static final int JDK_SEVERE = java.util.logging.Level.SEVERE.intValue();    // ERROR
-    private static final int JDK_WARNING = java.util.logging.Level.WARNING.intValue();  // WARN
-    private static final int JDK_INFO = java.util.logging.Level.INFO.intValue();        // INFO
-    private static final int JDK_CONFIG = java.util.logging.Level.CONFIG.intValue();    // INFO
-    private static final int JDK_FINE = java.util.logging.Level.FINE.intValue();        // DEBUG
-    private static final int JDK_FINER = java.util.logging.Level.FINER.intValue();      // DEBUG
-    private static final int JDK_FINEST = java.util.logging.Level.FINEST.intValue();    // TRACE
-    private static final int JDK_ALL = java.util.logging.Level.ALL.intValue();          // ALL
-
-    /**
-     * Converts a JDK logging Level to a Log4j logging Level.
-     *
-     * @param level JDK Level to convert.
-     * @return converted Level.
-     */
-    public static Level toLevel(final java.util.logging.Level level) {
-        final int value = level.intValue();
-        if (value == JDK_OFF) { // Integer.MAX_VALUE
-            return Level.OFF;
-        }
-        if (value == JDK_ALL) { // Integer.MIN_VALUE
-            return Level.ALL;
-        }
-        if (value <= JDK_FINEST) { // up to 300
-            return Level.TRACE;
-        }
-        if (value <= JDK_FINER) { // 301 to 400
-            return Level.DEBUG;
-        }
-        if (value <= JDK_FINE) { // 401 to 500
-            return Level.DEBUG;
-        }
-        if (value <= JDK_CONFIG) { // 501 to 700
-            return Level.INFO;
-        }
-        if (value <= JDK_INFO) { // 701 to 800
-            return Level.INFO;
-        }
-        if (value <= JDK_WARNING) { // 801 to 900
-            return Level.WARN;
-        }
-        if (value <= JDK_SEVERE) { // 901 to 1000
-            return Level.ERROR;
-        }
-        // 1001+
-        return Level.FATAL;
-    }
-
-    /**
-     * Converts a Log4j logging Level to a JDK logging Level.
-     *
-     * @param level Log4j Level to convert.
-     * @return converted Level.
-     */
-    public static java.util.logging.Level toJavaLevel(final Level level) {
-        if (level == Level.OFF) {
-            return java.util.logging.Level.OFF;
-        }
-        if (level == Level.TRACE) {
-            return java.util.logging.Level.FINEST;
-        }
-        if (level == Level.DEBUG) {
-            return java.util.logging.Level.FINE;
-        }
-        if (level == Level.INFO) {
-            return java.util.logging.Level.INFO;
-        }
-        if (level == Level.WARN) {
-            return java.util.logging.Level.WARNING;
-        }
-        if (level == Level.ERROR || level == Level.FATAL) {
-            return java.util.logging.Level.SEVERE;
-        }
-        if (level == Level.ALL) {
-            return java.util.logging.Level.ALL;
-        }
-        return java.util.logging.Level.parse(level.name());
-    }
-
-    private Levels() {
-    }
-}

http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/4cb8745a/log4j-jul/src/test/java/org/apache/logging/log4j/jul/LevelTranslatorTest.java
----------------------------------------------------------------------
diff --git a/log4j-jul/src/test/java/org/apache/logging/log4j/jul/LevelTranslatorTest.java b/log4j-jul/src/test/java/org/apache/logging/log4j/jul/LevelTranslatorTest.java
new file mode 100644
index 0000000..744e296
--- /dev/null
+++ b/log4j-jul/src/test/java/org/apache/logging/log4j/jul/LevelTranslatorTest.java
@@ -0,0 +1,66 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache license, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the license for the specific language governing permissions and
+ * limitations under the license.
+ */
+
+package org.apache.logging.log4j.jul;
+
+import java.util.Arrays;
+import java.util.Collection;
+
+import org.apache.logging.log4j.Level;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.junit.runners.Parameterized;
+
+import static org.junit.Assert.*;
+
+@RunWith(Parameterized.class)
+public class LevelTranslatorTest {
+
+    private final java.util.logging.Level level;
+    private final Level expectedLevel;
+
+    public LevelTranslatorTest(final java.util.logging.Level level, final Level expectedLevel) {
+        this.level = level;
+        this.expectedLevel = expectedLevel;
+    }
+
+    @Parameterized.Parameters
+    public static Collection<Object[]> data() {
+        return Arrays.asList(
+            new Object[][]{
+                {CustomJdkLevel.TEST, Level.INFO},
+                {CustomJdkLevel.DEFCON_2, Level.ERROR},
+                {CustomJdkLevel.DEFCON_1, Level.FATAL},
+                {java.util.logging.Level.OFF, Level.OFF},
+                {java.util.logging.Level.ALL, Level.ALL},
+                {java.util.logging.Level.SEVERE, Level.ERROR},
+                {java.util.logging.Level.WARNING, Level.WARN},
+                {java.util.logging.Level.INFO, Level.INFO},
+                {java.util.logging.Level.CONFIG, Level.INFO},
+                {java.util.logging.Level.FINE, Level.DEBUG},
+                {java.util.logging.Level.FINER, Level.DEBUG},
+                {java.util.logging.Level.FINEST, Level.TRACE}
+            }
+        );
+    }
+
+    @Test
+    public void testToLevel() throws Exception {
+        final Level actualLevel = LevelTranslator.toLevel(level);
+        assertEquals(expectedLevel, actualLevel);
+    }
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/4cb8745a/log4j-jul/src/test/java/org/apache/logging/log4j/jul/LevelsTest.java
----------------------------------------------------------------------
diff --git a/log4j-jul/src/test/java/org/apache/logging/log4j/jul/LevelsTest.java b/log4j-jul/src/test/java/org/apache/logging/log4j/jul/LevelsTest.java
deleted file mode 100644
index ae2e7e2..0000000
--- a/log4j-jul/src/test/java/org/apache/logging/log4j/jul/LevelsTest.java
+++ /dev/null
@@ -1,49 +0,0 @@
-package org.apache.logging.log4j.jul;
-
-import java.util.Arrays;
-import java.util.Collection;
-
-import org.apache.logging.log4j.Level;
-import org.junit.Test;
-import org.junit.runner.RunWith;
-import org.junit.runners.Parameterized;
-
-import static org.junit.Assert.*;
-
-@RunWith(Parameterized.class)
-public class LevelsTest {
-
-    private final java.util.logging.Level level;
-    private final Level expectedLevel;
-
-    public LevelsTest(final java.util.logging.Level level, final Level expectedLevel) {
-        this.level = level;
-        this.expectedLevel = expectedLevel;
-    }
-
-    @Parameterized.Parameters
-    public static Collection<Object[]> data() {
-        return Arrays.asList(
-            new Object[][]{
-                {CustomJdkLevel.TEST, Level.INFO},
-                {CustomJdkLevel.DEFCON_2, Level.ERROR},
-                {CustomJdkLevel.DEFCON_1, Level.FATAL},
-                {java.util.logging.Level.OFF, Level.OFF},
-                {java.util.logging.Level.ALL, Level.ALL},
-                {java.util.logging.Level.SEVERE, Level.ERROR},
-                {java.util.logging.Level.WARNING, Level.WARN},
-                {java.util.logging.Level.INFO, Level.INFO},
-                {java.util.logging.Level.CONFIG, Level.INFO},
-                {java.util.logging.Level.FINE, Level.DEBUG},
-                {java.util.logging.Level.FINER, Level.DEBUG},
-                {java.util.logging.Level.FINEST, Level.TRACE}
-            }
-        );
-    }
-
-    @Test
-    public void testToLevel() throws Exception {
-        final Level actualLevel = Levels.toLevel(level);
-        assertEquals(expectedLevel, actualLevel);
-    }
-}
\ No newline at end of file


[2/2] git commit: Simplify LevelTranslator using map lookups.

Posted by ma...@apache.org.
Simplify LevelTranslator using map lookups.


Project: http://git-wip-us.apache.org/repos/asf/logging-log4j2/repo
Commit: http://git-wip-us.apache.org/repos/asf/logging-log4j2/commit/545cdca8
Tree: http://git-wip-us.apache.org/repos/asf/logging-log4j2/tree/545cdca8
Diff: http://git-wip-us.apache.org/repos/asf/logging-log4j2/diff/545cdca8

Branch: refs/heads/master
Commit: 545cdca8eae1e5c61a5446415b441d09d928770e
Parents: 4cb8745
Author: Matt Sicker <ma...@apache.org>
Authored: Mon Sep 8 13:50:27 2014 -0500
Committer: Matt Sicker <ma...@apache.org>
Committed: Mon Sep 8 13:50:27 2014 -0500

----------------------------------------------------------------------
 .../logging/log4j/jul/LevelTranslator.java      | 61 ++++++++++++--------
 1 file changed, 37 insertions(+), 24 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/545cdca8/log4j-jul/src/main/java/org/apache/logging/log4j/jul/LevelTranslator.java
----------------------------------------------------------------------
diff --git a/log4j-jul/src/main/java/org/apache/logging/log4j/jul/LevelTranslator.java b/log4j-jul/src/main/java/org/apache/logging/log4j/jul/LevelTranslator.java
index 023be11..bc83457 100644
--- a/log4j-jul/src/main/java/org/apache/logging/log4j/jul/LevelTranslator.java
+++ b/log4j-jul/src/main/java/org/apache/logging/log4j/jul/LevelTranslator.java
@@ -17,6 +17,9 @@
 
 package org.apache.logging.log4j.jul;
 
+import java.util.IdentityHashMap;
+import java.util.Map;
+
 import org.apache.logging.log4j.Level;
 
 /**
@@ -26,7 +29,6 @@ import org.apache.logging.log4j.Level;
  */
 public final class LevelTranslator {
 
-    private static final int JDK_OFF = java.util.logging.Level.OFF.intValue();          // OFF
     private static final int JDK_SEVERE = java.util.logging.Level.SEVERE.intValue();    // ERROR
     private static final int JDK_WARNING = java.util.logging.Level.WARNING.intValue();  // WARN
     private static final int JDK_INFO = java.util.logging.Level.INFO.intValue();        // INFO
@@ -34,7 +36,31 @@ public final class LevelTranslator {
     private static final int JDK_FINE = java.util.logging.Level.FINE.intValue();        // DEBUG
     private static final int JDK_FINER = java.util.logging.Level.FINER.intValue();      // DEBUG
     private static final int JDK_FINEST = java.util.logging.Level.FINEST.intValue();    // TRACE
-    private static final int JDK_ALL = java.util.logging.Level.ALL.intValue();          // ALL
+
+    // standard level mappings
+    private static final Map<java.util.logging.Level, Level> JDK_TO_LOG4J =
+        new IdentityHashMap<java.util.logging.Level, Level>(10);
+    private static final Map<Level, java.util.logging.Level> LOG4J_TO_JDK =
+        new IdentityHashMap<Level, java.util.logging.Level>(10);
+
+    static {
+        JDK_TO_LOG4J.put(java.util.logging.Level.OFF, Level.OFF);
+        JDK_TO_LOG4J.put(java.util.logging.Level.FINEST, Level.TRACE);
+        JDK_TO_LOG4J.put(java.util.logging.Level.FINER, Level.DEBUG);
+        JDK_TO_LOG4J.put(java.util.logging.Level.FINE, Level.DEBUG);
+        JDK_TO_LOG4J.put(java.util.logging.Level.CONFIG, Level.INFO);
+        JDK_TO_LOG4J.put(java.util.logging.Level.INFO, Level.INFO);
+        JDK_TO_LOG4J.put(java.util.logging.Level.WARNING, Level.WARN);
+        JDK_TO_LOG4J.put(java.util.logging.Level.SEVERE, Level.ERROR);
+        JDK_TO_LOG4J.put(java.util.logging.Level.ALL, Level.ALL);
+        LOG4J_TO_JDK.put(Level.OFF, java.util.logging.Level.OFF);
+        LOG4J_TO_JDK.put(Level.TRACE, java.util.logging.Level.FINEST);
+        LOG4J_TO_JDK.put(Level.DEBUG, java.util.logging.Level.FINE);
+        LOG4J_TO_JDK.put(Level.INFO, java.util.logging.Level.INFO);
+        LOG4J_TO_JDK.put(Level.WARN, java.util.logging.Level.WARNING);
+        LOG4J_TO_JDK.put(Level.ERROR, java.util.logging.Level.SEVERE);
+        LOG4J_TO_JDK.put(Level.ALL, java.util.logging.Level.ALL);
+    }
 
     /**
      * Converts a JDK logging Level to a Log4j logging Level.
@@ -43,11 +69,15 @@ public final class LevelTranslator {
      * @return converted Level.
      */
     public static Level toLevel(final java.util.logging.Level level) {
+        final Level standardLevel = JDK_TO_LOG4J.get(level);
+        if (standardLevel != null) {
+            return standardLevel;
+        }
         final int value = level.intValue();
-        if (value == JDK_OFF) { // Integer.MAX_VALUE
+        if (value == Integer.MAX_VALUE) {
             return Level.OFF;
         }
-        if (value == JDK_ALL) { // Integer.MIN_VALUE
+        if (value == Integer.MIN_VALUE) {
             return Level.ALL;
         }
         if (value <= JDK_FINEST) { // up to 300
@@ -82,26 +112,9 @@ public final class LevelTranslator {
      * @return converted Level.
      */
     public static java.util.logging.Level toJavaLevel(final Level level) {
-        if (level == Level.OFF) {
-            return java.util.logging.Level.OFF;
-        }
-        if (level == Level.TRACE) {
-            return java.util.logging.Level.FINEST;
-        }
-        if (level == Level.DEBUG) {
-            return java.util.logging.Level.FINE;
-        }
-        if (level == Level.INFO) {
-            return java.util.logging.Level.INFO;
-        }
-        if (level == Level.WARN) {
-            return java.util.logging.Level.WARNING;
-        }
-        if (level == Level.ERROR || level == Level.FATAL) {
-            return java.util.logging.Level.SEVERE;
-        }
-        if (level == Level.ALL) {
-            return java.util.logging.Level.ALL;
+        final java.util.logging.Level standardLevel = LOG4J_TO_JDK.get(level);
+        if (standardLevel != null) {
+            return standardLevel;
         }
         return java.util.logging.Level.parse(level.name());
     }