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

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

commit d31e8dd3919e31c1c54ad2ce0a34d912bb1c83f8
Author: Gary Gregory <[email protected]>
AuthorDate: Tue Jan 18 12:21:55 2022 -0500

    Refactor to only set the logger level once instead of potentially twice.
---
 .../apache/logging/log4j/status/StatusLogger.java  | 37 ++++++++++++++++++----
 1 file changed, 30 insertions(+), 7 deletions(-)

diff --git 
a/log4j-api/src/main/java/org/apache/logging/log4j/status/StatusLogger.java 
b/log4j-api/src/main/java/org/apache/logging/log4j/status/StatusLogger.java
index cf7124b..86eee2a 100644
--- a/log4j-api/src/main/java/org/apache/logging/log4j/status/StatusLogger.java
+++ b/log4j-api/src/main/java/org/apache/logging/log4j/status/StatusLogger.java
@@ -101,18 +101,41 @@ public final class StatusLogger extends AbstractLogger {
 
     private int listenersLevel;
 
+    /**
+     * Constructs the singleton instance for the STATUS_LOGGER constant.
+     * <p>
+     * This is now the logger level is set:
+     * </p>
+     * <ol>
+     * <li>If the property {@value Constants#LOG4J2_DEBUG} is {@code "true"}, 
then use {@link Level#TRACE}, otherwise,</li>
+     * <li>Use {@link Level#ERROR}</li>
+     * </ol>
+     * <p>
+     * This is now the listener level is set:
+     * </p>
+     * <ol>
+     * <li>If the property {@value #DEFAULT_STATUS_LISTENER_LEVEL} is set, 
then use <em>it</em>, otherwise,</li>
+     * <li>Use {@link Level#WARN}</li>
+     * </ol>
+     * <p>
+     * See:
+     * <ol>
+     * <li>LOG4J2-1813 Provide shorter and more intuitive way to switch on 
Log4j internal debug logging. If system property
+     * "log4j2.debug" is defined, print all status logging.</li>
+     * <li>LOG4J2-3340 StatusLogger's log Level cannot be changed as 
advertised.</li>
+     * </ol>
+     * </p>
+     * 
+     * @param name The logger name.
+     * @param messageFactory The message factory.
+     */
     private StatusLogger(final String name, final MessageFactory 
messageFactory) {
         super(name, messageFactory);
         final String dateFormat = PROPS.getStringProperty(STATUS_DATE_FORMAT, 
Strings.EMPTY);
         final boolean showDateTime = !Strings.isEmpty(dateFormat);
-        this.logger = new SimpleLogger("StatusLogger", Level.ERROR, false, 
true, showDateTime, false,
-                dateFormat, messageFactory, PROPS, System.err);
+        final Level loggerLevel = isDebugPropertyEnabled() ? Level.TRACE : 
Level.ERROR;
+        this.logger = new SimpleLogger("StatusLogger", loggerLevel, false, 
true, showDateTime, false, dateFormat, messageFactory, PROPS, System.err);
         this.listenersLevel = Level.toLevel(DEFAULT_STATUS_LEVEL, 
Level.WARN).intLevel();
-
-        // LOG4J2-1813 if system property "log4j2.debug" is defined, print all 
status logging
-        if (isDebugPropertyEnabled()) {
-            logger.setLevel(Level.TRACE);
-        }
     }
 
     // LOG4J2-1813 if system property "log4j2.debug" is defined, print all 
status logging

Reply via email to