Skip to content

Commit a2590b4

Browse files
ban-xiuvy
authored andcommitted
Add debug logs for successful resource loading in Loader (#4060)
Co-authored-by: Volkan Yazıcı <volkan@yazi.ci>
1 parent b788154 commit a2590b4

File tree

2 files changed

+29
-2
lines changed

2 files changed

+29
-2
lines changed

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

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@ public static ClassLoader getClassLoader(final Class<?> class1, final Class<?> c
9494
LOGGER.trace("Trying to find [{}] using context class loader {}.", resource, classLoader);
9595
final URL url = classLoader.getResource(resource);
9696
if (url != null) {
97+
LOGGER.debug("Found [{}] at {} using context class loader.", resource, url);
9798
return url;
9899
}
99100
}
@@ -104,6 +105,7 @@ public static ClassLoader getClassLoader(final Class<?> class1, final Class<?> c
104105
LOGGER.trace("Trying to find [{}] using {} class loader.", resource, classLoader);
105106
final URL url = classLoader.getResource(resource);
106107
if (url != null) {
108+
LOGGER.debug("Found [{}] at {} using {} class loader.", resource, url, classLoader);
107109
return url;
108110
}
109111
}
@@ -112,6 +114,7 @@ public static ClassLoader getClassLoader(final Class<?> class1, final Class<?> c
112114
LOGGER.trace("Trying to find [{}] using {} class loader.", resource, defaultLoader);
113115
final URL url = defaultLoader.getResource(resource);
114116
if (url != null) {
117+
LOGGER.debug("Found [{}] at {} using {} class loader.", resource, url, defaultLoader);
115118
return url;
116119
}
117120
}
@@ -127,7 +130,11 @@ public static ClassLoader getClassLoader(final Class<?> class1, final Class<?> c
127130
// loader which the parent of the system class loader. Hence the
128131
// code below.
129132
LOGGER.trace("Trying to find [{}] using ClassLoader.getSystemResource().", resource);
130-
return ClassLoader.getSystemResource(resource);
133+
final URL url = ClassLoader.getSystemResource(resource);
134+
if (url != null) {
135+
LOGGER.debug("Found [{}] at {} using system class loader.", resource, url);
136+
}
137+
return url;
131138
}
132139

133140
/**
@@ -157,6 +164,7 @@ public static InputStream getResourceAsStream(final String resource, final Class
157164
LOGGER.trace("Trying to find [{}] using context class loader {}.", resource, classLoader);
158165
is = classLoader.getResourceAsStream(resource);
159166
if (is != null) {
167+
LOGGER.debug("Found [{}] using context class loader {}.", resource, classLoader);
160168
return is;
161169
}
162170
}
@@ -167,6 +175,7 @@ public static InputStream getResourceAsStream(final String resource, final Class
167175
LOGGER.trace("Trying to find [{}] using {} class loader.", resource, classLoader);
168176
is = classLoader.getResourceAsStream(resource);
169177
if (is != null) {
178+
LOGGER.debug("Found [{}] using {} class loader.", resource, classLoader);
170179
return is;
171180
}
172181
}
@@ -176,6 +185,7 @@ public static InputStream getResourceAsStream(final String resource, final Class
176185
LOGGER.trace("Trying to find [{}] using {} class loader.", resource, defaultLoader);
177186
is = defaultLoader.getResourceAsStream(resource);
178187
if (is != null) {
188+
LOGGER.debug("Found [{}] using {} class loader.", resource, defaultLoader);
179189
return is;
180190
}
181191
}
@@ -191,7 +201,11 @@ public static InputStream getResourceAsStream(final String resource, final Class
191201
// loader which the parent of the system class loader. Hence the
192202
// code below.
193203
LOGGER.trace("Trying to find [{}] using ClassLoader.getSystemResource().", resource);
194-
return ClassLoader.getSystemResourceAsStream(resource);
204+
final InputStream is = ClassLoader.getSystemResourceAsStream(resource);
205+
if (is != null) {
206+
LOGGER.debug("Found [{}] using system class loader.", resource);
207+
}
208+
return is;
195209
}
196210

197211
/**
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<entry xmlns="https://logging.apache.org/xml/ns"
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xsi:schemaLocation="
5+
https://logging.apache.org/xml/ns
6+
https://logging.apache.org/xml/ns/log4j-changelog-0.xsd"
7+
type="fixed">
8+
<issue id="4058" link="https://github.com/apache/logging-log4j2/issues/4058"/>
9+
<issue id="4060" link="https://github.com/apache/logging-log4j2/pull/4060"/>
10+
<description format="asciidoc">
11+
Added debug level logs for successful resource loading in `Loader` class.
12+
</description>
13+
</entry>

0 commit comments

Comments
 (0)