Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Deprecate log4j2.defaultStatusLevel property #2481

Merged
merged 2 commits into from
Apr 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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")
ppkarwasz marked this conversation as resolved.
Show resolved Hide resolved
@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);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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";

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<entry xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="https://logging.apache.org/xml/ns"
xsi:schemaLocation="https://logging.apache.org/xml/ns https://logging.apache.org/xml/ns/log4j-changelog-0.xsd"
type="changed">
<description format="asciidoc">Deprecate `log4j2.defaultStatusLevel` property in Log4j Core in favor of `log4j2.statusLoggerLevel`.</description>
</entry>
25 changes: 5 additions & 20 deletions src/site/antora/modules/ROOT/pages/manual/configuration.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -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]
----
Expand Down Expand Up @@ -2219,22 +2216,10 @@ 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
vy marked this conversation as resolved.
Show resolved Hide resolved
| WARN
| ERROR
|
The initial "listenersLevel" of the StatusLogger. If StatusLogger listeners are added, the "listenerLevel"
is changed to that of the most verbose listener. If any listeners are registered, the listenerLevel is
Expand Down