You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@logging.apache.org by rg...@apache.org on 2022/09/07 04:13:33 UTC

[logging-log4j2] branch master updated: LOG4J2-3572 - Add getExlicitLevel method to LoggerConfig

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

rgoers pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/logging-log4j2.git


The following commit(s) were added to refs/heads/master by this push:
     new 0218b1bc4f LOG4J2-3572 - Add getExlicitLevel method to LoggerConfig
0218b1bc4f is described below

commit 0218b1bc4fca14a54c2db0676d42ba701aab1d51
Author: Ralph Goers <rg...@apache.org>
AuthorDate: Tue Sep 6 21:12:25 2022 -0700

    LOG4J2-3572 - Add getExlicitLevel method to LoggerConfig
---
 .../logging/log4j/core/config/LoggerConfigTest.java | 21 +++++++++++++++++++++
 .../logging/log4j/core/config/LoggerConfig.java     | 12 ++++++++++--
 src/changes/changes.xml                             |  3 +++
 3 files changed, 34 insertions(+), 2 deletions(-)

diff --git a/log4j-core-test/src/test/java/org/apache/logging/log4j/core/config/LoggerConfigTest.java b/log4j-core-test/src/test/java/org/apache/logging/log4j/core/config/LoggerConfigTest.java
index 16769169bb..db7285f562 100644
--- a/log4j-core-test/src/test/java/org/apache/logging/log4j/core/config/LoggerConfigTest.java
+++ b/log4j-core-test/src/test/java/org/apache/logging/log4j/core/config/LoggerConfigTest.java
@@ -86,4 +86,25 @@ public class LoggerConfigTest {
             assertEquals(value, actualList.get(i).getValue(), "value[" + i + "]");
         }
     }
+
+    @Test
+    public void testLevel() {
+        Configuration configuration = new DefaultConfiguration();
+        LoggerConfig config1 = LoggerConfig.newBuilder()
+                .withLoggerName("org.apache.logging.log4j.test")
+                .withLevel(Level.ERROR)
+                .withAdditivity(false)
+                .withConfig(configuration)
+                .build();
+        LoggerConfig config2 = LoggerConfig.newBuilder()
+                .withLoggerName("org.apache.logging.log4j")
+                .withAdditivity(false)
+                .withConfig(configuration)
+                .build();
+        config1.setParent(config2);
+        assertEquals(config1.getLevel(), Level.ERROR, "Unexpected Level");
+        assertEquals(config1.getExplicitLevel(), Level.ERROR, "Unexpected explicit level");
+        assertEquals(config2.getLevel(), Level.ERROR, "Unexpected Level");
+        assertNull(config2.getExplicitLevel(),"Unexpected explicit level");
+    }
 }
diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/config/LoggerConfig.java b/log4j-core/src/main/java/org/apache/logging/log4j/core/config/LoggerConfig.java
index d786de8fe8..7e096f77af 100644
--- a/log4j-core/src/main/java/org/apache/logging/log4j/core/config/LoggerConfig.java
+++ b/log4j-core/src/main/java/org/apache/logging/log4j/core/config/LoggerConfig.java
@@ -384,6 +384,14 @@ public class LoggerConfig extends AbstractFilterable {
         return level == null ? parent == null ? Level.ERROR : parent.getLevel() : level;
     }
 
+    /**
+     * Allows callers to determine the Level assigned to this LoggerConfig.
+     * @return the Level associated with this LoggerConfig or null if none is set.
+     */
+    public Level getExplicitLevel() {
+        return level;
+    }
+
     /**
      * Returns the LogEventFactory.
      *
@@ -835,11 +843,11 @@ public class LoggerConfig extends AbstractFilterable {
             } else {
                 LOGGER.warn("levelAndRefs are only allowed in a properties configuration. The value is ignored.");
                 result.level = level;
-                result.refs = Arrays.asList(refs);
+                result.refs = refs != null ? Arrays.asList(refs) : new ArrayList<>();
             }
         } else {
             result.level = level;
-            result.refs = Arrays.asList(refs);
+            result.refs = refs != null ? Arrays.asList(refs) : new ArrayList<>();
         }
         return result;
     }
diff --git a/src/changes/changes.xml b/src/changes/changes.xml
index b76a274924..e803264113 100644
--- a/src/changes/changes.xml
+++ b/src/changes/changes.xml
@@ -202,6 +202,9 @@
       </action>
     </release>
     <release version="2.19.0" date="2022-MM-DD" description="GA Release 2.19.0">
+      <action issue="LOG4J2-3572" dev="rgeors" type="update">
+        Add getExlicitLevel method to LoggerConfig.
+      </action>
       <action issue="LOG4J2-3589" dev="rgoers" type="update">
         Allow Plugins to be injected with the LoggerContext reference.
       </action>