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/10/08 03:30:20 UTC

[2/2] git commit: Consolidate log4j-jul constants into a Constants class.

Consolidate log4j-jul constants into a Constants class.


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

Branch: refs/heads/master
Commit: 2a409753cceb48efd8c2ae35ba772d9f18b18b2d
Parents: 0fd2610
Author: Matt Sicker <ma...@apache.org>
Authored: Tue Oct 7 20:10:25 2014 -0500
Committer: Matt Sicker <ma...@apache.org>
Committed: Tue Oct 7 20:10:25 2014 -0500

----------------------------------------------------------------------
 .../org/apache/logging/log4j/jul/Constants.java | 44 ++++++++++++++++++++
 .../logging/log4j/jul/LevelConverter.java       |  2 +-
 .../logging/log4j/jul/LevelTranslator.java      |  8 +---
 .../apache/logging/log4j/jul/LogManager.java    | 15 ++-----
 .../apache/logging/log4j/jul/ApiLoggerTest.java |  4 +-
 5 files changed, 52 insertions(+), 21 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/2a409753/log4j-jul/src/main/java/org/apache/logging/log4j/jul/Constants.java
----------------------------------------------------------------------
diff --git a/log4j-jul/src/main/java/org/apache/logging/log4j/jul/Constants.java b/log4j-jul/src/main/java/org/apache/logging/log4j/jul/Constants.java
new file mode 100644
index 0000000..ad645b3
--- /dev/null
+++ b/log4j-jul/src/main/java/org/apache/logging/log4j/jul/Constants.java
@@ -0,0 +1,44 @@
+/*
+ * 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;
+
+/**
+ * Constants for the JUL adapter.
+ *
+ * @since 2.1
+ */
+public final class Constants {
+
+    /**
+     * Name of the Log4j property to set to override the {@link AbstractLoggerAdapter} to be used. By
+     * default, when this property is not set, an appropriate LoggerAdaptor is chosen based on the presence of
+     * {@code log4j-core}.
+     */
+    public static final String LOGGER_ADAPTOR_PROPERTY = "log4j.jul.LoggerAdapter";
+    /**
+     * The Log4j property to set to a custom implementation of {@link org.apache.logging.log4j.jul.LevelConverter}. The specified class must have
+     * a default constructor.
+     */
+    public static final String LEVEL_CONVERTER_PROPERTY = "log4j.jul.levelConverter";
+
+    static final String CORE_LOGGER_CLASS_NAME = "org.apache.logging.log4j.core.Logger";
+    static final String CORE_LOGGER_ADAPTER_CLASS_NAME = "org.apache.logging.log4j.jul.CoreLoggerAdapter";
+    static final String API_LOGGER_ADAPTER_CLASS_NAME = "org.apache.logging.log4j.jul.ApiLoggerAdapter";
+
+    private Constants() {
+    }
+}

http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/2a409753/log4j-jul/src/main/java/org/apache/logging/log4j/jul/LevelConverter.java
----------------------------------------------------------------------
diff --git a/log4j-jul/src/main/java/org/apache/logging/log4j/jul/LevelConverter.java b/log4j-jul/src/main/java/org/apache/logging/log4j/jul/LevelConverter.java
index 003b84e..22ddad6 100644
--- a/log4j-jul/src/main/java/org/apache/logging/log4j/jul/LevelConverter.java
+++ b/log4j-jul/src/main/java/org/apache/logging/log4j/jul/LevelConverter.java
@@ -23,7 +23,7 @@ import org.apache.logging.log4j.Level;
  * Strategy interface to convert between custom Log4j {@link Level Levels} and JUL
  * {@link java.util.logging.Level Levels}.
  *
- * @see LevelTranslator#LEVEL_CONVERTER_PROPERTY
+ * @see Constants#LEVEL_CONVERTER_PROPERTY
  * @since 2.1
  */
 public interface LevelConverter {

http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/2a409753/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 bcb0218..c64c380 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
@@ -31,12 +31,6 @@ import org.apache.logging.log4j.util.PropertiesUtil;
 public final class LevelTranslator {
 
     /**
-     * The Log4j property to set to a custom implementation of {@link LevelConverter}. The specified class must have
-     * a default constructor.
-     */
-    public static final String LEVEL_CONVERTER_PROPERTY = "log4j.jul.levelConverter";
-
-    /**
      * Custom Log4j level corresponding to the {@link java.util.logging.Level#FINEST} logging level. This maps to a
      * level more specific than {@link org.apache.logging.log4j.Level#TRACE}.
      */
@@ -53,7 +47,7 @@ public final class LevelTranslator {
 
     static {
         final String levelConverterClassName =
-            PropertiesUtil.getProperties().getStringProperty(LEVEL_CONVERTER_PROPERTY);
+            PropertiesUtil.getProperties().getStringProperty(Constants.LEVEL_CONVERTER_PROPERTY);
         if (levelConverterClassName != null) {
             LevelConverter levelConverter;
             try {

http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/2a409753/log4j-jul/src/main/java/org/apache/logging/log4j/jul/LogManager.java
----------------------------------------------------------------------
diff --git a/log4j-jul/src/main/java/org/apache/logging/log4j/jul/LogManager.java b/log4j-jul/src/main/java/org/apache/logging/log4j/jul/LogManager.java
index 42f0c4b..10f8fdb 100644
--- a/log4j-jul/src/main/java/org/apache/logging/log4j/jul/LogManager.java
+++ b/log4j-jul/src/main/java/org/apache/logging/log4j/jul/LogManager.java
@@ -39,13 +39,6 @@ import org.apache.logging.log4j.util.PropertiesUtil;
  */
 public class LogManager extends java.util.logging.LogManager {
 
-    /**
-     * Name of the Log4j property to set to override the {@link AbstractLoggerAdapter} to be used. By
-     * default, when this property is not set, an appropriate LoggerAdaptor is chosen based on the presence of
-     * {@code log4j-core}.
-     */
-    public static final String LOGGER_ADAPTOR_PROPERTY = "log4j.jul.LoggerAdapter";
-
     private static final org.apache.logging.log4j.Logger LOGGER = StatusLogger.getLogger();
     private final AbstractLoggerAdapter loggerAdapter;
 
@@ -53,7 +46,7 @@ public class LogManager extends java.util.logging.LogManager {
         super();
         AbstractLoggerAdapter adapter = null;
         final String overrideAdaptorClassName =
-            PropertiesUtil.getProperties().getStringProperty(LOGGER_ADAPTOR_PROPERTY);
+            PropertiesUtil.getProperties().getStringProperty(Constants.LOGGER_ADAPTOR_PROPERTY);
         if (overrideAdaptorClassName != null) {
             try {
                 LOGGER.info("Trying to use LoggerAdaptor [{}] specified by Log4j property.", overrideAdaptorClassName);
@@ -67,10 +60,10 @@ public class LogManager extends java.util.logging.LogManager {
             String adapterClassName;
             try {
                 // find out if log4j-core is available
-                LoaderUtil.loadClass("org.apache.logging.log4j.core.Logger");
-                adapterClassName = "org.apache.logging.log4j.jul.CoreLoggerAdapter";
+                LoaderUtil.loadClass(Constants.CORE_LOGGER_CLASS_NAME);
+                adapterClassName = Constants.CORE_LOGGER_ADAPTER_CLASS_NAME;
             } catch (final ClassNotFoundException ignored) {
-                adapterClassName = "org.apache.logging.log4j.jul.ApiLoggerAdapter";
+                adapterClassName = Constants.API_LOGGER_ADAPTER_CLASS_NAME;
             }
             LOGGER.debug("Attempting to use {}", adapterClassName);
             try {

http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/2a409753/log4j-jul/src/test/java/org/apache/logging/log4j/jul/ApiLoggerTest.java
----------------------------------------------------------------------
diff --git a/log4j-jul/src/test/java/org/apache/logging/log4j/jul/ApiLoggerTest.java b/log4j-jul/src/test/java/org/apache/logging/log4j/jul/ApiLoggerTest.java
index 54cc13b..7ad1470 100644
--- a/log4j-jul/src/test/java/org/apache/logging/log4j/jul/ApiLoggerTest.java
+++ b/log4j-jul/src/test/java/org/apache/logging/log4j/jul/ApiLoggerTest.java
@@ -33,7 +33,7 @@ public class ApiLoggerTest extends AbstractLoggerTest {
     @BeforeClass
     public static void setUpClass() {
         System.setProperty("java.util.logging.manager", LogManager.class.getName());
-        System.setProperty(LogManager.LOGGER_ADAPTOR_PROPERTY, ApiLoggerAdapter.class.getName());
+        System.setProperty(Constants.LOGGER_ADAPTOR_PROPERTY, ApiLoggerAdapter.class.getName());
     }
 
     @Before
@@ -65,4 +65,4 @@ public class ApiLoggerTest extends AbstractLoggerTest {
     public void testSetLevelFails() throws Exception {
         logger.setLevel(null);
     }
-}
\ No newline at end of file
+}