diff --git a/log4j-core-test/src/test/java/org/apache/logging/log4j/core/config/xml/XmlConfigurationPropsTest.java b/log4j-core-test/src/test/java/org/apache/logging/log4j/core/config/xml/XmlConfigurationPropsTest.java index e7a13f12edc..3437f787b8a 100644 --- a/log4j-core-test/src/test/java/org/apache/logging/log4j/core/config/xml/XmlConfigurationPropsTest.java +++ b/log4j-core-test/src/test/java/org/apache/logging/log4j/core/config/xml/XmlConfigurationPropsTest.java @@ -72,9 +72,17 @@ void testNoProps(final Configuration config) { } @Test + @SetTestProperty(key = StatusLogger.DEFAULT_STATUS_LISTENER_LEVEL, value = "INFO") @SetTestProperty(key = Constants.LOG4J_DEFAULT_STATUS_LEVEL, value = "WARN") @LoggerContextSource(value = CONFIG1) void testDefaultStatus(final Configuration config) { + testConfiguration(config, CONFIG1_NAME, Level.INFO, null); + } + + @Test + @SetTestProperty(key = Constants.LOG4J_DEFAULT_STATUS_LEVEL, value = "WARN") + @LoggerContextSource(value = CONFIG1) + void testDeprecatedDefaultStatus(final Configuration config) { testConfiguration(config, CONFIG1_NAME, Level.WARN, null); } 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 014ebcca013..d7ee730c5f5 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 @@ -76,6 +76,7 @@ import org.apache.logging.log4j.core.util.WatchManager; import org.apache.logging.log4j.core.util.Watcher; import org.apache.logging.log4j.core.util.WatcherFactory; +import org.apache.logging.log4j.status.StatusLogger; import org.apache.logging.log4j.util.LoaderUtil; import org.apache.logging.log4j.util.PropertiesUtil; @@ -479,8 +480,11 @@ public void setup() { } protected Level getDefaultStatus() { - final String statusLevel = PropertiesUtil.getProperties() - .getStringProperty(Constants.LOG4J_DEFAULT_STATUS_LEVEL, Level.ERROR.name()); + final PropertiesUtil properties = PropertiesUtil.getProperties(); + String statusLevel = properties.getStringProperty(StatusLogger.DEFAULT_STATUS_LISTENER_LEVEL); + if (statusLevel == null) { + statusLevel = properties.getStringProperty(Constants.LOG4J_DEFAULT_STATUS_LEVEL, Level.ERROR.name()); + } try { return Level.toLevel(statusLevel); } catch (final Exception ex) { diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/util/Constants.java b/log4j-core/src/main/java/org/apache/logging/log4j/core/util/Constants.java index e0b0c698341..b2381b06d79 100644 --- a/log4j-core/src/main/java/org/apache/logging/log4j/core/util/Constants.java +++ b/log4j-core/src/main/java/org/apache/logging/log4j/core/util/Constants.java @@ -35,7 +35,10 @@ public final class Constants { /** * Property name for the default status (internal log4j logging) level to use if not specified in configuration. + * @deprecated since 2.24.0 use + * {@link org.apache.logging.log4j.status.StatusLogger#DEFAULT_STATUS_LISTENER_LEVEL} instead. */ + @Deprecated public static final String LOG4J_DEFAULT_STATUS_LEVEL = "Log4jDefaultStatusLevel"; /** diff --git a/src/changelog/.2.x.x/deprecate_log4j2_default_status_level.xml b/src/changelog/.2.x.x/deprecate_log4j2_default_status_level.xml new file mode 100644 index 00000000000..fe8e5d3ffb8 --- /dev/null +++ b/src/changelog/.2.x.x/deprecate_log4j2_default_status_level.xml @@ -0,0 +1,7 @@ + + + Deprecate `log4j2.defaultStatusLevel` property in Log4j Core in favor of `log4j2.statusLoggerLevel`. + diff --git a/src/site/antora/modules/ROOT/pages/manual/configuration.adoc b/src/site/antora/modules/ROOT/pages/manual/configuration.adoc index 343a7c9505d..0aefb411af2 100644 --- a/src/site/antora/modules/ROOT/pages/manual/configuration.adoc +++ b/src/site/antora/modules/ROOT/pages/manual/configuration.adoc @@ -1715,13 +1715,10 @@ protected final static Logger logger = StatusLogger.getLogger(); Since StatusLogger implements the Log4j 2 API's Logger interface, all the normal Logger methods may be used. -When configuring Log4j it is sometimes necessary to view the generated -status events. This can be accomplished by adding the status attribute -to the configuration element or a default value can be provided by -setting the "Log4jDefaultStatusLevel" system property. Valid values of -the status attribute are "trace", "debug", "info", "warn", "error" and -"fatal". The following configuration has the status attribute set to -debug. +When configuring Log4j it is sometimes necessary to view the generated status events. +This can be accomplished by adding the status attribute to the configuration element or a default value can be provided by setting the xref:statusLoggerLevel["log4j2.statusLoggerLevel"] system property. +Valid values of the status attribute are "trace", "debug", "info", "warn", "error" and "fatal". +The following configuration has the status attribute set to debug. [source,xml] ---- @@ -2219,18 +2216,6 @@ The following is a list of available global configuration properties. Note that until a listener is registered. In practice, a listener is registered when a configuration is found, and from that point onwards, status messages are only sent to the listeners (depending on their statusLevel). -| [[defaultStatusLevel]]log4j2.defaultStatusLevel - ([[Log4jDefaultStatusLevel]]Log4jDefaultStatusLevel) -| LOG4J_DEFAULT_STATUS_LEVEL -| ERROR -| - The StatusLogger logs events that occur in the logging system to the console. - During configuration, AbstractConfiguration registers a StatusConsoleListener with the StatusLogger that may - redirect status log events from the default console output to a file. - The listener also supports fine-grained filtering. - This system property specifies the default status log level for the listener to use if the configuration does not specify a status level. - Note: this property is used by the log4j-core implementation only after a configuration file has been found. - | [[statusLoggerLevel]]log4j2.statusLoggerLevel ([[log4j2.StatusLogger.level]]log4j2.StatusLogger.level) | LOG4J_STATUS_LOGGER_LEVEL