Skip to content

Commit 4e00ea4

Browse files
committed
Deprecate log4j2.defaultStatusLevel property
The Log4j system property `log4j2.defaultStatusLevel` has almost the same purpose as the `log4j2.statusLoggerLevel`: * the `log4j2.statusLoggerLevel` property sets the level of the fallback status logger listener **before** a configuration is parsed, * the `log4j2.defaultStatusLevel` property sets the level of the fallback status logger listener **after** a configuration is parsed (unless the configuration has a `status` attribute). Removing one of them makes `-Dlog4j2.statusLoggerLevel=WARN` a viable less verbose alternative to `-Dlog4j2.debug`.
1 parent 3236a0c commit 4e00ea4

File tree

5 files changed

+28
-21
lines changed

5 files changed

+28
-21
lines changed

log4j-core-test/src/test/java/org/apache/logging/log4j/core/config/xml/XmlConfigurationPropsTest.java

+8
Original file line numberDiff line numberDiff line change
@@ -72,9 +72,17 @@ void testNoProps(final Configuration config) {
7272
}
7373

7474
@Test
75+
@SetTestProperty(key = StatusLogger.DEFAULT_STATUS_LISTENER_LEVEL, value = "INFO")
7576
@SetTestProperty(key = Constants.LOG4J_DEFAULT_STATUS_LEVEL, value = "WARN")
7677
@LoggerContextSource(value = CONFIG1)
7778
void testDefaultStatus(final Configuration config) {
79+
testConfiguration(config, CONFIG1_NAME, Level.INFO, null);
80+
}
81+
82+
@Test
83+
@SetTestProperty(key = Constants.LOG4J_DEFAULT_STATUS_LEVEL, value = "WARN")
84+
@LoggerContextSource(value = CONFIG1)
85+
void testDeprecatedDefaultStatus(final Configuration config) {
7886
testConfiguration(config, CONFIG1_NAME, Level.WARN, null);
7987
}
8088

log4j-core/src/main/java/org/apache/logging/log4j/core/config/AbstractConfiguration.java

+6-2
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@
7676
import org.apache.logging.log4j.core.util.WatchManager;
7777
import org.apache.logging.log4j.core.util.Watcher;
7878
import org.apache.logging.log4j.core.util.WatcherFactory;
79+
import org.apache.logging.log4j.status.StatusLogger;
7980
import org.apache.logging.log4j.util.LoaderUtil;
8081
import org.apache.logging.log4j.util.PropertiesUtil;
8182

@@ -479,8 +480,11 @@ public void setup() {
479480
}
480481

481482
protected Level getDefaultStatus() {
482-
final String statusLevel = PropertiesUtil.getProperties()
483-
.getStringProperty(Constants.LOG4J_DEFAULT_STATUS_LEVEL, Level.ERROR.name());
483+
final PropertiesUtil properties = PropertiesUtil.getProperties();
484+
String statusLevel = properties.getStringProperty(StatusLogger.DEFAULT_STATUS_LISTENER_LEVEL);
485+
if (statusLevel == null) {
486+
statusLevel = properties.getStringProperty(Constants.LOG4J_DEFAULT_STATUS_LEVEL, Level.ERROR.name());
487+
}
484488
try {
485489
return Level.toLevel(statusLevel);
486490
} catch (final Exception ex) {

log4j-core/src/main/java/org/apache/logging/log4j/core/util/Constants.java

+3
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,10 @@ public final class Constants {
3535

3636
/**
3737
* Property name for the default status (internal log4j logging) level to use if not specified in configuration.
38+
* @deprecated since 2.24.0 use
39+
* {@link org.apache.logging.log4j.status.StatusLogger#DEFAULT_STATUS_LISTENER_LEVEL} instead.
3840
*/
41+
@Deprecated
3942
public static final String LOG4J_DEFAULT_STATUS_LEVEL = "Log4jDefaultStatusLevel";
4043

4144
/**
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<entry xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3+
xmlns="https://logging.apache.org/xml/ns"
4+
xsi:schemaLocation="https://logging.apache.org/xml/ns https://logging.apache.org/xml/ns/log4j-changelog-0.xsd"
5+
type="changed">
6+
<description format="asciidoc">Deprecate `log4j2.defaultStatusLevel` property in Log4j Core in favor of `log4j2.statusLoggerLevel`.</description>
7+
</entry>

src/site/antora/modules/ROOT/pages/manual/configuration.adoc

+4-19
Original file line numberDiff line numberDiff line change
@@ -1715,13 +1715,10 @@ protected final static Logger logger = StatusLogger.getLogger();
17151715
Since StatusLogger implements the Log4j 2 API's Logger interface, all
17161716
the normal Logger methods may be used.
17171717
1718-
When configuring Log4j it is sometimes necessary to view the generated
1719-
status events. This can be accomplished by adding the status attribute
1720-
to the configuration element or a default value can be provided by
1721-
setting the "Log4jDefaultStatusLevel" system property. Valid values of
1722-
the status attribute are "trace", "debug", "info", "warn", "error" and
1723-
"fatal". The following configuration has the status attribute set to
1724-
debug.
1718+
When configuring Log4j it is sometimes necessary to view the generated status events.
1719+
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.
1720+
Valid values of the status attribute are "trace", "debug", "info", "warn", "error" and "fatal".
1721+
The following configuration has the status attribute set to debug.
17251722
17261723
[source,xml]
17271724
----
@@ -2219,18 +2216,6 @@ The following is a list of available global configuration properties. Note that
22192216
until a listener is registered. In practice, a listener is registered when a configuration is found,
22202217
and from that point onwards, status messages are only sent to the listeners (depending on their statusLevel).
22212218
2222-
| [[defaultStatusLevel]]log4j2.defaultStatusLevel
2223-
([[Log4jDefaultStatusLevel]]Log4jDefaultStatusLevel)
2224-
| LOG4J_DEFAULT_STATUS_LEVEL
2225-
| ERROR
2226-
|
2227-
The StatusLogger logs events that occur in the logging system to the console.
2228-
During configuration, AbstractConfiguration registers a StatusConsoleListener with the StatusLogger that may
2229-
redirect status log events from the default console output to a file.
2230-
The listener also supports fine-grained filtering.
2231-
This system property specifies the default status log level for the listener to use if the configuration does not specify a status level.
2232-
Note: this property is used by the log4j-core implementation only after a configuration file has been found.
2233-
22342219
| [[statusLoggerLevel]]log4j2.statusLoggerLevel
22352220
([[log4j2.StatusLogger.level]]log4j2.StatusLogger.level)
22362221
| LOG4J_STATUS_LOGGER_LEVEL

0 commit comments

Comments
 (0)