openjpa-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From strub...@apache.org
Subject [openjpa] branch master updated: OPENJPA-2842 log4j vs log4j2 logging fixed
Date Tue, 01 Dec 2020 10:38:03 GMT
This is an automated email from the ASF dual-hosted git repository.

struberg pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/openjpa.git


The following commit(s) were added to refs/heads/master by this push:
     new 61b3077  OPENJPA-2842 log4j vs log4j2 logging fixed
61b3077 is described below

commit 61b30777d4e83646325006175f918d9fb2ef45c9
Author: Mark Struberg <struberg@apache.org>
AuthorDate: Tue Dec 1 11:35:29 2020 +0100

    OPENJPA-2842 log4j vs log4j2 logging fixed
    
    * introduce new 'log4j2' LogFactory
    * switch back old 'log4j' LogFactory to log4j-1.x
---
 openjpa-lib/pom.xml                                   |  5 +++++
 .../apache/openjpa/lib/conf/ConfigurationImpl.java    |  1 +
 .../{Log4JLogFactory.java => Log4J2LogFactory.java}   |  8 ++++----
 .../org/apache/openjpa/lib/log/Log4JLogFactory.java   | 19 ++++++++++---------
 pom.xml                                               | 11 ++++++++++-
 5 files changed, 30 insertions(+), 14 deletions(-)

diff --git a/openjpa-lib/pom.xml b/openjpa-lib/pom.xml
index 4b95357..3d6e85a 100644
--- a/openjpa-lib/pom.xml
+++ b/openjpa-lib/pom.xml
@@ -57,6 +57,11 @@
             <scope>provided</scope>
         </dependency>
         <dependency>
+            <groupId>org.apache.logging.log4j</groupId>
+            <artifactId>log4j-1.2-api</artifactId>
+            <scope>provided</scope>
+        </dependency>
+        <dependency>
             <groupId>org.slf4j</groupId>
             <artifactId>slf4j-api</artifactId>
             <scope>provided</scope>
diff --git a/openjpa-lib/src/main/java/org/apache/openjpa/lib/conf/ConfigurationImpl.java
b/openjpa-lib/src/main/java/org/apache/openjpa/lib/conf/ConfigurationImpl.java
index d7d54c3..56b978b 100644
--- a/openjpa-lib/src/main/java/org/apache/openjpa/lib/conf/ConfigurationImpl.java
+++ b/openjpa-lib/src/main/java/org/apache/openjpa/lib/conf/ConfigurationImpl.java
@@ -157,6 +157,7 @@ public class ConfigurationImpl
             "openjpa", LogFactoryImpl.class.getName(),
             "commons", "org.apache.openjpa.lib.log.CommonsLogFactory",
             "log4j", "org.apache.openjpa.lib.log.Log4JLogFactory",
+            "log4j2", "org.apache.openjpa.lib.log.Log4J2LogFactory",
             "slf4j", "org.apache.openjpa.lib.log.SLF4JLogFactory",
             "jul", "org.apache.openjpa.lib.log.JULLogFactory",
             "none", NoneLogFactory.class.getName(),
diff --git a/openjpa-lib/src/main/java/org/apache/openjpa/lib/log/Log4JLogFactory.java b/openjpa-lib/src/main/java/org/apache/openjpa/lib/log/Log4J2LogFactory.java
similarity index 94%
copy from openjpa-lib/src/main/java/org/apache/openjpa/lib/log/Log4JLogFactory.java
copy to openjpa-lib/src/main/java/org/apache/openjpa/lib/log/Log4J2LogFactory.java
index dd2651c..72aa069 100644
--- a/openjpa-lib/src/main/java/org/apache/openjpa/lib/log/Log4JLogFactory.java
+++ b/openjpa-lib/src/main/java/org/apache/openjpa/lib/log/Log4J2LogFactory.java
@@ -22,11 +22,11 @@ import org.apache.logging.log4j.LogManager;
 import org.apache.logging.log4j.Logger;
 
 /**
- * {@link LogFactory} implementation that delegates to the Log4J framework.
+ * {@link LogFactory} implementation that delegates to the Log4J-2.x framework.
+ * It's configuration key is {@code openjpa.Log=log4j2}.
  *
- * @author Patrick Linskey
  */
-public class Log4JLogFactory extends LogFactoryAdapter {
+public class Log4J2LogFactory extends LogFactoryAdapter {
 
     @Override
     protected Log newLogAdapter(String channel) {
@@ -34,7 +34,7 @@ public class Log4JLogFactory extends LogFactoryAdapter {
     }
 
     /**
-     * Adapts a Log4J logger to the {@link org.apache.openjpa.lib.log.Log}
+     * Adapts a Log4J2 logger to the {@link Log}
      * interface.
      */
     public static class LogAdapter implements Log {
diff --git a/openjpa-lib/src/main/java/org/apache/openjpa/lib/log/Log4JLogFactory.java b/openjpa-lib/src/main/java/org/apache/openjpa/lib/log/Log4JLogFactory.java
index dd2651c..4bf377c 100644
--- a/openjpa-lib/src/main/java/org/apache/openjpa/lib/log/Log4JLogFactory.java
+++ b/openjpa-lib/src/main/java/org/apache/openjpa/lib/log/Log4JLogFactory.java
@@ -18,11 +18,12 @@
  */
 package org.apache.openjpa.lib.log;
 
-import org.apache.logging.log4j.LogManager;
-import org.apache.logging.log4j.Logger;
+import org.apache.log4j.Level;
+import org.apache.log4j.LogManager;
+import org.apache.log4j.Logger;
 
 /**
- * {@link LogFactory} implementation that delegates to the Log4J framework.
+ * {@link LogFactory} implementation that delegates to the Log4J 1.x framework.
  *
  * @author Patrick Linskey
  */
@@ -30,7 +31,7 @@ public class Log4JLogFactory extends LogFactoryAdapter {
 
     @Override
     protected Log newLogAdapter(String channel) {
-        return new LogAdapter(LogManager.getLogger(channel));
+        return new LogAdapter((Logger) LogManager.getLogger(channel));
     }
 
     /**
@@ -51,27 +52,27 @@ public class Log4JLogFactory extends LogFactoryAdapter {
 
         @Override
         public boolean isTraceEnabled() {
-            return _log.isTraceEnabled();
+            return _log.isEnabledFor(Level.DEBUG);
         }
 
         @Override
         public boolean isInfoEnabled() {
-            return _log.isInfoEnabled();
+            return _log.isEnabledFor(Level.INFO);
         }
 
         @Override
         public boolean isWarnEnabled() {
-            return _log.isWarnEnabled();
+            return _log.isEnabledFor(Level.WARN);
         }
 
         @Override
         public boolean isErrorEnabled() {
-            return _log.isErrorEnabled();
+            return _log.isEnabledFor(Level.ERROR);
         }
 
         @Override
         public boolean isFatalEnabled() {
-            return _log.isFatalEnabled();
+            return _log.isEnabledFor(Level.FATAL);
         }
 
         @Override
diff --git a/pom.xml b/pom.xml
index cf6c223..a03c659 100644
--- a/pom.xml
+++ b/pom.xml
@@ -96,6 +96,8 @@
 
         <xbean.version>4.18</xbean.version>
         <bval.version>1.1.2</bval.version>
+        <log4j2.version>2.14.0</log4j2.version>
+
         <jmock.version>2.9.0</jmock.version>
         <automatic-module-name>-SUBMODULES-NEED-TO-OVERRIDE-THIS-</automatic-module-name>
     </properties>
@@ -1782,9 +1784,16 @@
             <dependency>
                 <groupId>org.apache.logging.log4j</groupId>
                 <artifactId>log4j-core</artifactId>
-                <version>2.11.1</version>
+                <version>${log4j2.version}</version>
             </dependency>
             <dependency>
+                <!-- for compiling against log4j-1.2.x we use the compat layer from log4j2
-->
+                <groupId>org.apache.logging.log4j</groupId>
+                <artifactId>log4j-1.2-api</artifactId>
+                <version>${log4j2.version}</version>
+            </dependency>
+
+            <dependency>
               <groupId>io.fabric8</groupId>
               <artifactId>kubernetes-client</artifactId>
               <version>${kubernetes-client.version}</version>


Mime
View raw message