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