From 2392544e6c5016df540b68c50c6ff6f7bb2eabda Mon Sep 17 00:00:00 2001 From: Lukasz Spyra Date: Sun, 23 Jul 2023 09:56:42 +0200 Subject: [PATCH 1/5] Change default StatusLogger level from Level.ERROR to Level.WARN --- .../java/org/apache/logging/log4j/status/StatusLogger.java | 4 ++-- 1 file changed, 2 insertions(+), 2 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 d25ef822e50..71001cbe5c7 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 @@ -113,7 +113,7 @@ public final class StatusLogger extends AbstractLogger { *

*
    *
  1. If the property {@value Constants#LOG4J2_DEBUG} is {@code "true"}, then use {@link Level#TRACE}, otherwise,
  2. - *
  3. Use {@link Level#ERROR}
  4. + *
  5. Use {@link Level#WARN}
  6. *
*

* This is now the listener level is set: @@ -139,7 +139,7 @@ private StatusLogger( final MessageFactory messageFactory, final SimpleLoggerFactory loggerFactory) { super(name, messageFactory); - final Level loggerLevel = DEBUG_ENABLED ? Level.TRACE : Level.ERROR; + final Level loggerLevel = DEBUG_ENABLED ? Level.TRACE : Level.WARN; this.logger = loggerFactory.createSimpleLogger("StatusLogger", loggerLevel, messageFactory, System.err); this.listenersLevel = Level.toLevel(DEFAULT_STATUS_LEVEL, Level.WARN).intLevel(); } From c34d74a860a7d33b0b751e8cd99e7d60657f0de5 Mon Sep 17 00:00:00 2001 From: Lukasz Spyra Date: Mon, 24 Jul 2023 07:17:53 +0200 Subject: [PATCH 2/5] Change default StatusConfiguration level from Level.ERROR to Level.WARN --- .../log4j/core/config/status/StatusConfiguration.java | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/config/status/StatusConfiguration.java b/log4j-core/src/main/java/org/apache/logging/log4j/core/config/status/StatusConfiguration.java index 606a8e8ec8d..d8c88d09842 100644 --- a/log4j-core/src/main/java/org/apache/logging/log4j/core/config/status/StatusConfiguration.java +++ b/log4j-core/src/main/java/org/apache/logging/log4j/core/config/status/StatusConfiguration.java @@ -39,7 +39,7 @@ public class StatusConfiguration { @SuppressWarnings("UseOfSystemOutOrSystemErr") private static final PrintStream DEFAULT_STREAM = System.out; - private static final Level DEFAULT_STATUS = Level.ERROR; + private static final Level DEFAULT_STATUS = Level.WARN; private static final Verbosity DEFAULT_VERBOSITY = Verbosity.QUIET; private final Collection errorMessages = new LinkedBlockingQueue<>(); @@ -124,6 +124,7 @@ private PrintStream parseStreamName(final String name) throws URISyntaxException /** * Specifies the logging level by name to use for filtering StatusLogger messages. + * Defaults to {@link Level#WARN} for invalid level name. * * @param status name of logger level to filter below. * @return {@code this} @@ -132,8 +133,8 @@ private PrintStream parseStreamName(final String name) throws URISyntaxException public StatusConfiguration withStatus(final String status) { this.status = Level.toLevel(status, null); if (this.status == null) { - this.error("Invalid status level specified: " + status + ". Defaulting to ERROR."); - this.status = Level.ERROR; + this.error("Invalid status level specified: " + status + ". Defaulting to WARN."); + this.status = Level.WARN; } return this; } From 6724044492a9b1783ea017d42e86fd0c3f2e36ad Mon Sep 17 00:00:00 2001 From: Lukasz Spyra Date: Mon, 24 Jul 2023 09:54:32 +0200 Subject: [PATCH 3/5] Change default status from ERROR to WARN in AbstractConfiguration It's method getDefaultStatus() is initially used, when configuring StatusConfiguration from found config file. Status doesn't change if file misses status key node. --- .../logging/log4j/core/config/AbstractConfiguration.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/config/AbstractConfiguration.java b/log4j-core/src/main/java/org/apache/logging/log4j/core/config/AbstractConfiguration.java index 013182d9c79..9128ee32037 100644 --- a/log4j-core/src/main/java/org/apache/logging/log4j/core/config/AbstractConfiguration.java +++ b/log4j-core/src/main/java/org/apache/logging/log4j/core/config/AbstractConfiguration.java @@ -471,11 +471,11 @@ public void setup() { protected Level getDefaultStatus() { final String statusLevel = PropertiesUtil.getProperties().getStringProperty( - Constants.LOG4J_DEFAULT_STATUS_LEVEL, Level.ERROR.name()); + Constants.LOG4J_DEFAULT_STATUS_LEVEL, Level.WARN.name()); try { return Level.toLevel(statusLevel); } catch (final Exception ex) { - return Level.ERROR; + return Level.WARN; } } From e7310c79c87926ebf7091e3aded9b22ec3837abc Mon Sep 17 00:00:00 2001 From: Lukasz Spyra Date: Sun, 8 Oct 2023 14:52:16 +0200 Subject: [PATCH 4/5] Revert default level of StatusLogger to Level.ERROR --- .../java/org/apache/logging/log4j/status/StatusLogger.java | 4 ++-- .../logging/log4j/core/config/AbstractConfiguration.java | 4 ++-- .../log4j/core/config/status/StatusConfiguration.java | 7 +++---- 3 files changed, 7 insertions(+), 8 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 71001cbe5c7..d25ef822e50 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 @@ -113,7 +113,7 @@ public final class StatusLogger extends AbstractLogger { *

*
    *
  1. If the property {@value Constants#LOG4J2_DEBUG} is {@code "true"}, then use {@link Level#TRACE}, otherwise,
  2. - *
  3. Use {@link Level#WARN}
  4. + *
  5. Use {@link Level#ERROR}
  6. *
*

* This is now the listener level is set: @@ -139,7 +139,7 @@ private StatusLogger( final MessageFactory messageFactory, final SimpleLoggerFactory loggerFactory) { super(name, messageFactory); - final Level loggerLevel = DEBUG_ENABLED ? Level.TRACE : Level.WARN; + final Level loggerLevel = DEBUG_ENABLED ? Level.TRACE : Level.ERROR; this.logger = loggerFactory.createSimpleLogger("StatusLogger", loggerLevel, messageFactory, System.err); this.listenersLevel = Level.toLevel(DEFAULT_STATUS_LEVEL, Level.WARN).intLevel(); } diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/config/AbstractConfiguration.java b/log4j-core/src/main/java/org/apache/logging/log4j/core/config/AbstractConfiguration.java index 9128ee32037..013182d9c79 100644 --- a/log4j-core/src/main/java/org/apache/logging/log4j/core/config/AbstractConfiguration.java +++ b/log4j-core/src/main/java/org/apache/logging/log4j/core/config/AbstractConfiguration.java @@ -471,11 +471,11 @@ public void setup() { protected Level getDefaultStatus() { final String statusLevel = PropertiesUtil.getProperties().getStringProperty( - Constants.LOG4J_DEFAULT_STATUS_LEVEL, Level.WARN.name()); + Constants.LOG4J_DEFAULT_STATUS_LEVEL, Level.ERROR.name()); try { return Level.toLevel(statusLevel); } catch (final Exception ex) { - return Level.WARN; + return Level.ERROR; } } diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/config/status/StatusConfiguration.java b/log4j-core/src/main/java/org/apache/logging/log4j/core/config/status/StatusConfiguration.java index d8c88d09842..606a8e8ec8d 100644 --- a/log4j-core/src/main/java/org/apache/logging/log4j/core/config/status/StatusConfiguration.java +++ b/log4j-core/src/main/java/org/apache/logging/log4j/core/config/status/StatusConfiguration.java @@ -39,7 +39,7 @@ public class StatusConfiguration { @SuppressWarnings("UseOfSystemOutOrSystemErr") private static final PrintStream DEFAULT_STREAM = System.out; - private static final Level DEFAULT_STATUS = Level.WARN; + private static final Level DEFAULT_STATUS = Level.ERROR; private static final Verbosity DEFAULT_VERBOSITY = Verbosity.QUIET; private final Collection errorMessages = new LinkedBlockingQueue<>(); @@ -124,7 +124,6 @@ private PrintStream parseStreamName(final String name) throws URISyntaxException /** * Specifies the logging level by name to use for filtering StatusLogger messages. - * Defaults to {@link Level#WARN} for invalid level name. * * @param status name of logger level to filter below. * @return {@code this} @@ -133,8 +132,8 @@ private PrintStream parseStreamName(final String name) throws URISyntaxException public StatusConfiguration withStatus(final String status) { this.status = Level.toLevel(status, null); if (this.status == null) { - this.error("Invalid status level specified: " + status + ". Defaulting to WARN."); - this.status = Level.WARN; + this.error("Invalid status level specified: " + status + ". Defaulting to ERROR."); + this.status = Level.ERROR; } return this; } From b3412a82cbbdd8544ff8c9effe90cb65795c89d8 Mon Sep 17 00:00:00 2001 From: Lukasz Spyra Date: Tue, 10 Oct 2023 14:17:09 +0200 Subject: [PATCH 5/5] Log error when configuration file is missing required dependencies --- .../apache/logging/log4j/core/config/ConfigurationFactory.java | 2 +- .../logging/log4j/core/config/status/StatusConfiguration.java | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/config/ConfigurationFactory.java b/log4j-core/src/main/java/org/apache/logging/log4j/core/config/ConfigurationFactory.java index c12375a1eb3..cccba118b52 100644 --- a/log4j-core/src/main/java/org/apache/logging/log4j/core/config/ConfigurationFactory.java +++ b/log4j-core/src/main/java/org/apache/logging/log4j/core/config/ConfigurationFactory.java @@ -528,7 +528,7 @@ private Configuration getConfiguration(final LoggerContext loggerContext, final final ConfigurationSource source = ConfigurationSource.fromResource(configName, loader); if (source != null) { if (!factory.isActive()) { - LOGGER.warn("Found configuration file {} for inactive ConfigurationFactory {}", configName, factory.getClass().getName()); + LOGGER.error("Found configuration file {} for inactive ConfigurationFactory {} - missing dependencies", configName, factory.getClass().getName()); } return factory.getConfiguration(loggerContext, source); } diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/config/status/StatusConfiguration.java b/log4j-core/src/main/java/org/apache/logging/log4j/core/config/status/StatusConfiguration.java index 606a8e8ec8d..1f28ce4b503 100644 --- a/log4j-core/src/main/java/org/apache/logging/log4j/core/config/status/StatusConfiguration.java +++ b/log4j-core/src/main/java/org/apache/logging/log4j/core/config/status/StatusConfiguration.java @@ -124,6 +124,7 @@ private PrintStream parseStreamName(final String name) throws URISyntaxException /** * Specifies the logging level by name to use for filtering StatusLogger messages. + * Defaults to {@link Level#ERROR} for invalid level name. * * @param status name of logger level to filter below. * @return {@code this}