You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@logging.apache.org by ra...@apache.org on 2026/10/01 17:50:58 UTC
(logging-log4j2) 29/33: Improve missing logging provider diagnostic (#4321)
This is an automated email from the ASF dual-hosted git repository.
ramanathan1504 pushed a commit to branch port/2.27.0-fixes-to-2.26.x
in repository https://gitbox.apache.org/repos/asf/logging-log4j2.git
commit 79baab7187b95c867b89acceda6b42ba7ef65301
Author: akashchamp <11...@users.noreply.github.com>
AuthorDate: Thu Sep 24 08:50:48 2026 +0530
Improve missing logging provider diagnostic (#4321)
* Improve missing logging provider diagnostic
* Point the missing-provider diagnostic at the #impl anchor
The installation guide's root opens several screens above the
provider-implementation section; #3415 names the #impl anchor
specifically. Applies to the runtime message, its test assertion, and
the identical sample output in the installation guide.
Also credits this PR in the changelog entry.
---------
Co-authored-by: Ramanathan <ra...@apache.org>
(cherry picked from commit f07ea190ca1ed2a4773aa0ae61f86c84dbe49615)
---
.../org/apache/logging/log4j/util/ProviderUtilTest.java | 12 ++++++++----
.../java/org/apache/logging/log4j/util/ProviderUtil.java | 5 ++++-
.../.2.x.x/3415_improve_missing_provider_diagnostic.xml | 13 +++++++++++++
src/site/antora/modules/ROOT/pages/manual/installation.adoc | 2 ++
4 files changed, 27 insertions(+), 5 deletions(-)
diff --git a/log4j-api-test/src/test/java/org/apache/logging/log4j/util/ProviderUtilTest.java b/log4j-api-test/src/test/java/org/apache/logging/log4j/util/ProviderUtilTest.java
index 8d67050cc2..9bfc70c07d 100644
--- a/log4j-api-test/src/test/java/org/apache/logging/log4j/util/ProviderUtilTest.java
+++ b/log4j-api-test/src/test/java/org/apache/logging/log4j/util/ProviderUtilTest.java
@@ -25,6 +25,7 @@ import java.util.Properties;
import java.util.regex.Pattern;
import java.util.stream.Stream;
import org.apache.logging.log4j.TestProvider;
+import org.apache.logging.log4j.simple.internal.SimpleProvider;
import org.apache.logging.log4j.spi.Provider;
import org.apache.logging.log4j.test.TestLogger;
import org.apache.logging.log4j.test.TestLoggerContextFactory;
@@ -56,13 +57,16 @@ class ProviderUtilTest {
}
@Test
- void should_have_a_fallback_provider() {
+ void should_log_diagnostic_and_use_simple_provider_when_no_provider_is_available() {
final PropertiesUtil properties = new PropertiesUtil(new Properties());
assertThat(ProviderUtil.selectProvider(properties, NO_PROVIDERS, statusLogger))
.as("check selected provider")
- .isNotNull();
- // An error for the absence of providers
- assertHasErrorOrWarning(statusLogger);
+ .isInstanceOf(SimpleProvider.class);
+ assertThat(statusLogger.getEntries())
+ .contains(" ERROR Log4j API could not find a logging provider.\n"
+ + "Log4j API will use Simple Logger by default.\n"
+ + "See https://logging.apache.org/log4j/2.x/manual/installation.html#impl "
+ + "for instructions on how to configure Log4j API.");
}
@Test
diff --git a/log4j-api/src/main/java/org/apache/logging/log4j/util/ProviderUtil.java b/log4j-api/src/main/java/org/apache/logging/log4j/util/ProviderUtil.java
index d66c35c34c..14cf3e1a46 100644
--- a/log4j-api/src/main/java/org/apache/logging/log4j/util/ProviderUtil.java
+++ b/log4j-api/src/main/java/org/apache/logging/log4j/util/ProviderUtil.java
@@ -245,7 +245,10 @@ public final class ProviderUtil {
final Comparator<Provider> comparator = Comparator.comparing(Provider::getPriority);
switch (providers.size()) {
case 0:
- statusLogger.error("Log4j API could not find a logging provider.");
+ statusLogger.error("Log4j API could not find a logging provider.\n"
+ + "Log4j API will use Simple Logger by default.\n"
+ + "See https://logging.apache.org/log4j/2.x/manual/installation.html#impl "
+ + "for instructions on how to configure Log4j API.");
break;
case 1:
break;
diff --git a/src/changelog/.2.x.x/3415_improve_missing_provider_diagnostic.xml b/src/changelog/.2.x.x/3415_improve_missing_provider_diagnostic.xml
new file mode 100644
index 0000000000..e4ef14ec6f
--- /dev/null
+++ b/src/changelog/.2.x.x/3415_improve_missing_provider_diagnostic.xml
@@ -0,0 +1,13 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<entry xmlns="https://logging.apache.org/xml/ns"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="
+ https://logging.apache.org/xml/ns
+ https://logging.apache.org/xml/ns/log4j-changelog-0.xsd"
+ type="changed">
+ <issue id="3415" link="https://github.com/apache/logging-log4j2/issues/3415"/>
+ <issue id="4321" link="https://github.com/apache/logging-log4j2/pull/4321"/>
+ <description format="asciidoc">
+ Improve the diagnostic shown when no Log4j API provider is available
+ </description>
+</entry>
diff --git a/src/site/antora/modules/ROOT/pages/manual/installation.adoc b/src/site/antora/modules/ROOT/pages/manual/installation.adoc
index 71a700dd0a..8c96c8fc72 100644
--- a/src/site/antora/modules/ROOT/pages/manual/installation.adoc
+++ b/src/site/antora/modules/ROOT/pages/manual/installation.adoc
@@ -186,6 +186,8 @@ xref:manual/status-logger.adoc[Status Logger] to avoid its unintentional usages:
----
2024-10-03T11:53:34.281462230Z main ERROR Log4j API could not find a logging provider.
+Log4j API will use Simple Logger by default.
+See https://logging.apache.org/log4j/2.x/manual/installation.html#impl for instructions on how to configure Log4j API.
----
To remove the warning and confirm that you want to use Simple Logger, add a