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 2021/05/29 20:11:00 UTC

[logging-log4j2] branch release-2.x updated: [LOG4J2-3095] Category.setLevel should accept null value.

This is an automated email from the ASF dual-hosted git repository.

ggregory pushed a commit to branch release-2.x
in repository https://gitbox.apache.org/repos/asf/logging-log4j2.git


The following commit(s) were added to refs/heads/release-2.x by this push:
     new be4165e  [LOG4J2-3095] Category.setLevel should accept null value.
be4165e is described below

commit be4165ecf99bd30518ed847b18c2b70d4b3f3b7f
Author: Gary Gregory <ga...@gmail.com>
AuthorDate: Sat May 29 16:10:55 2021 -0400

    [LOG4J2-3095] Category.setLevel should accept null value.
---
 log4j-1.2-api/src/main/java/org/apache/log4j/Category.java    |  8 ++++++--
 .../src/test/java/org/apache/log4j/CategoryTest.java          | 11 +++++++++++
 src/changes/changes.xml                                       |  3 +++
 3 files changed, 20 insertions(+), 2 deletions(-)

diff --git a/log4j-1.2-api/src/main/java/org/apache/log4j/Category.java b/log4j-1.2-api/src/main/java/org/apache/log4j/Category.java
index 0211791..7b13e91 100644
--- a/log4j-1.2-api/src/main/java/org/apache/log4j/Category.java
+++ b/log4j-1.2-api/src/main/java/org/apache/log4j/Category.java
@@ -224,8 +224,12 @@ public class Category {
         return getEffectiveLevel();
     }
 
+    private String getLevelStr(final Priority priority) {
+        return priority == null ? null : priority.levelStr;
+    }
+
     public void setLevel(final Level level) {
-        setLevel(level.levelStr);
+        setLevel(getLevelStr(level));
     }
 
     public final Level getPriority() {
@@ -233,7 +237,7 @@ public class Category {
     }
 
     public void setPriority(final Priority priority) {
-        setLevel(priority.levelStr);
+        setLevel(getLevelStr(priority));
     }
 
     private void setLevel(final String levelStr) {
diff --git a/log4j-1.2-api/src/test/java/org/apache/log4j/CategoryTest.java b/log4j-1.2-api/src/test/java/org/apache/log4j/CategoryTest.java
index b25aeb4..33e1e57 100644
--- a/log4j-1.2-api/src/test/java/org/apache/log4j/CategoryTest.java
+++ b/log4j-1.2-api/src/test/java/org/apache/log4j/CategoryTest.java
@@ -165,6 +165,17 @@ public class CategoryTest {
         logger.setPriority(debug);
     }
 
+    /**
+     * Tests setPriority(Priority).
+     *
+     * @deprecated
+     */
+    @Deprecated
+    @Test
+    public void testSetPriorityNull() {
+        Logger.getLogger("org.example.foo").setPriority(null);
+    }
+
     @Test
     public void testClassName() {
         final Category category = Category.getInstance("TestCategory");
diff --git a/src/changes/changes.xml b/src/changes/changes.xml
index 9eed86a..0074c6c 100644
--- a/src/changes/changes.xml
+++ b/src/changes/changes.xml
@@ -93,6 +93,9 @@
       <action issue="LOG4J2-2965" dev="ckozak" type="fix">
         Fixed a deadlock between the AsyncLoggerContextSelector and java.util.logging.LogManager by updating Disruptor to 3.4.4.
       </action>
+      <action issue="LOG4J2-3095" dev="ggregory" type="fix" due-to="Kenny MacLeod, Gary Gregory">
+        Category.setLevel should accept null value.
+      </action>
       <!-- UPDATES -->
       <action dev="ggregory" type="update">
         - org.eclipse.persistence:javax.persistence ............. 2.1.1 -> 2.2.1