This is an automated email from the ASF dual-hosted git repository.

vy pushed a commit to branch 2.x
in repository https://gitbox.apache.org/repos/asf/logging-log4j2.git


The following commit(s) were added to refs/heads/2.x by this push:
     new c5396fc4d5 Add debug logs for successful resource loading in `Loader` 
(#4060)
c5396fc4d5 is described below

commit c5396fc4d5983be852f73c238890d41fe348c360
Author: LBS <[email protected]>
AuthorDate: Mon Mar 16 23:43:28 2026 +0800

    Add debug logs for successful resource loading in `Loader` (#4060)
    
    Co-authored-by: Volkan Yazıcı <[email protected]>
---
 .../org/apache/logging/log4j/core/util/Loader.java     | 18 ++++++++++++++++--
 .../add_debug_logs_for_successful_resource_loading.xml | 13 +++++++++++++
 2 files changed, 29 insertions(+), 2 deletions(-)

diff --git 
a/log4j-core/src/main/java/org/apache/logging/log4j/core/util/Loader.java 
b/log4j-core/src/main/java/org/apache/logging/log4j/core/util/Loader.java
index 4ae5d46335..98663a9ea2 100644
--- a/log4j-core/src/main/java/org/apache/logging/log4j/core/util/Loader.java
+++ b/log4j-core/src/main/java/org/apache/logging/log4j/core/util/Loader.java
@@ -94,6 +94,7 @@ public final class Loader {
                 LOGGER.trace("Trying to find [{}] using context class loader 
{}.", resource, classLoader);
                 final URL url = classLoader.getResource(resource);
                 if (url != null) {
+                    LOGGER.debug("Found [{}] at {} using context class 
loader.", resource, url);
                     return url;
                 }
             }
@@ -104,6 +105,7 @@ public final class Loader {
                 LOGGER.trace("Trying to find [{}] using {} class loader.", 
resource, classLoader);
                 final URL url = classLoader.getResource(resource);
                 if (url != null) {
+                    LOGGER.debug("Found [{}] at {} using {} class loader.", 
resource, url, classLoader);
                     return url;
                 }
             }
@@ -112,6 +114,7 @@ public final class Loader {
                 LOGGER.trace("Trying to find [{}] using {} class loader.", 
resource, defaultLoader);
                 final URL url = defaultLoader.getResource(resource);
                 if (url != null) {
+                    LOGGER.debug("Found [{}] at {} using {} class loader.", 
resource, url, defaultLoader);
                     return url;
                 }
             }
@@ -127,7 +130,11 @@ public final class Loader {
         // loader which the parent of the system class loader. Hence the
         // code below.
         LOGGER.trace("Trying to find [{}] using 
ClassLoader.getSystemResource().", resource);
-        return ClassLoader.getSystemResource(resource);
+        final URL url = ClassLoader.getSystemResource(resource);
+        if (url != null) {
+            LOGGER.debug("Found [{}] at {} using system class loader.", 
resource, url);
+        }
+        return url;
     }
 
     /**
@@ -157,6 +164,7 @@ public final class Loader {
                 LOGGER.trace("Trying to find [{}] using context class loader 
{}.", resource, classLoader);
                 is = classLoader.getResourceAsStream(resource);
                 if (is != null) {
+                    LOGGER.debug("Found [{}] using context class loader {}.", 
resource, classLoader);
                     return is;
                 }
             }
@@ -167,6 +175,7 @@ public final class Loader {
                 LOGGER.trace("Trying to find [{}] using {} class loader.", 
resource, classLoader);
                 is = classLoader.getResourceAsStream(resource);
                 if (is != null) {
+                    LOGGER.debug("Found [{}] using {} class loader.", 
resource, classLoader);
                     return is;
                 }
             }
@@ -176,6 +185,7 @@ public final class Loader {
                 LOGGER.trace("Trying to find [{}] using {} class loader.", 
resource, defaultLoader);
                 is = defaultLoader.getResourceAsStream(resource);
                 if (is != null) {
+                    LOGGER.debug("Found [{}] using {} class loader.", 
resource, defaultLoader);
                     return is;
                 }
             }
@@ -191,7 +201,11 @@ public final class Loader {
         // loader which the parent of the system class loader. Hence the
         // code below.
         LOGGER.trace("Trying to find [{}] using 
ClassLoader.getSystemResource().", resource);
-        return ClassLoader.getSystemResourceAsStream(resource);
+        final InputStream is = ClassLoader.getSystemResourceAsStream(resource);
+        if (is != null) {
+            LOGGER.debug("Found [{}] using system class loader.", resource);
+        }
+        return is;
     }
 
     /**
diff --git 
a/src/changelog/.2.x.x/add_debug_logs_for_successful_resource_loading.xml 
b/src/changelog/.2.x.x/add_debug_logs_for_successful_resource_loading.xml
new file mode 100644
index 0000000000..445100bf51
--- /dev/null
+++ b/src/changelog/.2.x.x/add_debug_logs_for_successful_resource_loading.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="added">
+    <issue id="4058" 
link="https://github.com/apache/logging-log4j2/issues/4058"/>
+    <issue id="4060" 
link="https://github.com/apache/logging-log4j2/pull/4060"/>
+    <description format="asciidoc">
+        Added debug level logs for successful resource loading in `Loader` 
class to show where resources are found
+    </description>
+</entry>

Reply via email to