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 2022/01/18 17:21:59 UTC

[logging-log4j2] branch release-2.x updated: Refactor to only set the logger level once instead of potentially twice.

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 a55b144  Refactor to only set the logger level once instead of potentially twice.
a55b144 is described below

commit a55b14490dfe2b8f4de3b652690598be694f864d
Author: Gary Gregory <ga...@gmail.com>
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 645b215..32accf9 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