Skip to content

Commit 4545f34

Browse files
committed
Merge pull request #371 from kazuki43zoo/issues/369_isDebugEnabled-3.2.x
[3.2.x] #369: Modify to use the Log#isDebugEnabled()
2 parents 0e9c048 + ac7c2bf commit 4545f34

File tree

8 files changed

+79
-28
lines changed

8 files changed

+79
-28
lines changed

src/main/java/org/apache/ibatis/executor/loader/ResultLoaderMap.java

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -155,10 +155,13 @@ private LoadPair(final String property, MetaObject metaResultObject, ResultLoade
155155

156156
this.configurationFactory = resultLoader.configuration.getConfigurationFactory();
157157
} else {
158-
this.getLogger().debug("Property [" + this.property + "] of ["
159-
+ metaResultObject.getOriginalObject().getClass() + "] cannot be loaded "
160-
+ "after deserialization. Make sure it's loaded before serializing "
161-
+ "forenamed object.");
158+
Log log = this.getLogger();
159+
if (log.isDebugEnabled()) {
160+
log.debug("Property [" + this.property + "] of ["
161+
+ metaResultObject.getOriginalObject().getClass() + "] cannot be loaded "
162+
+ "after deserialization. Make sure it's loaded before serializing "
163+
+ "forenamed object.");
164+
}
162165
}
163166
}
164167
}

src/main/java/org/apache/ibatis/executor/loader/cglib/CglibProxyFactory.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,9 @@ private static Object crateProxy(Class<?> type, Callback callback, List<Class<?>
7575
try {
7676
type.getDeclaredMethod(WRITE_REPLACE_METHOD);
7777
// ObjectOutputStream will call writeReplace of objects returned by writeReplace
78-
log.debug(WRITE_REPLACE_METHOD + " method was found on bean " + type + ", make sure it returns this");
78+
if (log.isDebugEnabled()) {
79+
log.debug(WRITE_REPLACE_METHOD + " method was found on bean " + type + ", make sure it returns this");
80+
}
7981
} catch (NoSuchMethodException e) {
8082
enhancer.setInterfaces(new Class[]{WriteReplaceInterface.class});
8183
} catch (SecurityException e) {

src/main/java/org/apache/ibatis/executor/loader/javassist/JavassistProxyFactory.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,9 @@ private static Object crateProxy(Class<?> type, MethodHandler callback, List<Cla
7575
try {
7676
type.getDeclaredMethod(WRITE_REPLACE_METHOD);
7777
// ObjectOutputStream will call writeReplace of objects returned by writeReplace
78-
log.debug(WRITE_REPLACE_METHOD + " method was found on bean " + type + ", make sure it returns this");
78+
if (log.isDebugEnabled()) {
79+
log.debug(WRITE_REPLACE_METHOD + " method was found on bean " + type + ", make sure it returns this");
80+
}
7981
} catch (NoSuchMethodException e) {
8082
enhancer.setInterfaces(new Class[]{WriteReplaceInterface.class});
8183
} catch (SecurityException e) {

src/main/java/org/apache/ibatis/io/DefaultVFS.java

Lines changed: 48 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,9 @@ public List<String> list(URL url, String path) throws IOException {
6161
URL jarUrl = findJarForResource(url);
6262
if (jarUrl != null) {
6363
is = jarUrl.openStream();
64-
log.debug("Listing " + url);
64+
if (log.isDebugEnabled()) {
65+
log.debug("Listing " + url);
66+
}
6567
resources = listResources(new JarInputStream(is), path);
6668
}
6769
else {
@@ -72,9 +74,13 @@ public List<String> list(URL url, String path) throws IOException {
7274
// referenced by the URL isn't actually a JAR
7375
is = url.openStream();
7476
JarInputStream jarInput = new JarInputStream(is);
75-
log.debug("Listing " + url);
77+
if (log.isDebugEnabled()) {
78+
log.debug("Listing " + url);
79+
}
7680
for (JarEntry entry; (entry = jarInput.getNextJarEntry()) != null;) {
77-
log.debug("Jar entry: " + entry.getName());
81+
if (log.isDebugEnabled()) {
82+
log.debug("Jar entry: " + entry.getName());
83+
}
7884
children.add(entry.getName());
7985
}
8086
}
@@ -91,7 +97,9 @@ public List<String> list(URL url, String path) throws IOException {
9197
BufferedReader reader = new BufferedReader(new InputStreamReader(is));
9298
List<String> lines = new ArrayList<String>();
9399
for (String line; (line = reader.readLine()) != null;) {
94-
log.debug("Reader entry: " + line);
100+
if (log.isDebugEnabled()) {
101+
log.debug("Reader entry: " + line);
102+
}
95103
lines.add(line);
96104
if (getResources(path + "/" + line).isEmpty()) {
97105
lines.clear();
@@ -100,7 +108,9 @@ public List<String> list(URL url, String path) throws IOException {
100108
}
101109

102110
if (!lines.isEmpty()) {
103-
log.debug("Listing " + url);
111+
if (log.isDebugEnabled()) {
112+
log.debug("Listing " + url);
113+
}
104114
children.addAll(lines);
105115
}
106116
}
@@ -112,9 +122,13 @@ public List<String> list(URL url, String path) throws IOException {
112122
*/
113123
if ("file".equals(url.getProtocol())) {
114124
File file = new File(url.getFile());
115-
log.debug("Listing directory " + file.getAbsolutePath());
125+
if (log.isDebugEnabled()) {
126+
log.debug("Listing directory " + file.getAbsolutePath());
127+
}
116128
if (file.isDirectory()) {
117-
log.debug("Listing " + url);
129+
if (log.isDebugEnabled()) {
130+
log.debug("Listing " + url);
131+
}
118132
children = Arrays.asList(file.list());
119133
}
120134
}
@@ -175,7 +189,9 @@ protected List<String> listResources(JarInputStream jar, String path) throws IOE
175189

176190
// Check file name
177191
if (name.startsWith(path)) {
178-
log.debug("Found resource: " + name);
192+
if (log.isDebugEnabled()) {
193+
log.debug("Found resource: " + name);
194+
}
179195
resources.add(name.substring(1)); // Trim leading slash
180196
}
181197
}
@@ -194,13 +210,17 @@ protected List<String> listResources(JarInputStream jar, String path) throws IOE
194210
* @throws MalformedURLException
195211
*/
196212
protected URL findJarForResource(URL url) throws MalformedURLException {
197-
log.debug("Find JAR URL: " + url);
213+
if (log.isDebugEnabled()) {
214+
log.debug("Find JAR URL: " + url);
215+
}
198216

199217
// If the file part of the URL is itself a URL, then that URL probably points to the JAR
200218
try {
201219
for (;;) {
202220
url = new URL(url.getFile());
203-
log.debug("Inner URL: " + url);
221+
if (log.isDebugEnabled()) {
222+
log.debug("Inner URL: " + url);
223+
}
204224
}
205225
} catch (MalformedURLException e) {
206226
// This will happen at some point and serves as a break in the loop
@@ -211,10 +231,14 @@ protected URL findJarForResource(URL url) throws MalformedURLException {
211231
int index = jarUrl.lastIndexOf(".jar");
212232
if (index >= 0) {
213233
jarUrl.setLength(index + 4);
214-
log.debug("Extracted JAR URL: " + jarUrl);
234+
if (log.isDebugEnabled()) {
235+
log.debug("Extracted JAR URL: " + jarUrl);
236+
}
215237
}
216238
else {
217-
log.debug("Not a JAR: " + jarUrl);
239+
if (log.isDebugEnabled()) {
240+
log.debug("Not a JAR: " + jarUrl);
241+
}
218242
return null;
219243
}
220244

@@ -226,7 +250,9 @@ protected URL findJarForResource(URL url) throws MalformedURLException {
226250
}
227251
else {
228252
// WebLogic fix: check if the URL's file exists in the filesystem.
229-
log.debug("Not a JAR: " + jarUrl);
253+
if (log.isDebugEnabled()) {
254+
log.debug("Not a JAR: " + jarUrl);
255+
}
230256
jarUrl.replace(0, jarUrl.length(), testUrl.getFile());
231257
File file = new File(jarUrl.toString());
232258

@@ -240,7 +266,9 @@ protected URL findJarForResource(URL url) throws MalformedURLException {
240266
}
241267

242268
if (file.exists()) {
243-
log.debug("Trying real file: " + file.getAbsolutePath());
269+
if (log.isDebugEnabled()) {
270+
log.debug("Trying real file: " + file.getAbsolutePath());
271+
}
244272
testUrl = file.toURI().toURL();
245273
if (isJar(testUrl)) {
246274
return testUrl;
@@ -251,7 +279,9 @@ protected URL findJarForResource(URL url) throws MalformedURLException {
251279
log.warn("Invalid JAR URL: " + jarUrl);
252280
}
253281

254-
log.debug("Not a JAR: " + jarUrl);
282+
if (log.isDebugEnabled()) {
283+
log.debug("Not a JAR: " + jarUrl);
284+
}
255285
return null;
256286
}
257287

@@ -288,7 +318,9 @@ protected boolean isJar(URL url, byte[] buffer) {
288318
is = url.openStream();
289319
is.read(buffer, 0, JAR_MAGIC.length);
290320
if (Arrays.equals(buffer, JAR_MAGIC)) {
291-
log.debug("Found JAR: " + url);
321+
if (log.isDebugEnabled()) {
322+
log.debug("Found JAR: " + url);
323+
}
292324
return true;
293325
}
294326
} catch (Exception e) {

src/main/java/org/apache/ibatis/io/ResolverUtil.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -247,7 +247,9 @@ protected void addIfMatching(Test test, String fqn) {
247247
try {
248248
String externalName = fqn.substring(0, fqn.indexOf('.')).replace('/', '.');
249249
ClassLoader loader = getClassLoader();
250-
log.debug("Checking to see if class " + externalName + " matches criteria [" + test + "]");
250+
if (log.isDebugEnabled()) {
251+
log.debug("Checking to see if class " + externalName + " matches criteria [" + test + "]");
252+
}
251253

252254
Class<?> type = loader.loadClass(externalName);
253255
if (test.matches(type)) {

src/main/java/org/apache/ibatis/io/VFS.java

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,10 @@ public static VFS getInstance() {
6565
try {
6666
vfs = impl.newInstance();
6767
if (vfs == null || !vfs.isValid()) {
68-
log.debug("VFS implementation " + impl.getName() +
68+
if (log.isDebugEnabled()) {
69+
log.debug("VFS implementation " + impl.getName() +
6970
" is not valid in this environment.");
71+
}
7072
}
7173
} catch (InstantiationException e) {
7274
log.error("Failed to instantiate " + impl, e);
@@ -77,7 +79,9 @@ public static VFS getInstance() {
7779
}
7880
}
7981

80-
log.debug("Using VFS adapter " + vfs.getClass().getName());
82+
if (log.isDebugEnabled()) {
83+
log.debug("Using VFS adapter " + vfs.getClass().getName());
84+
}
8185
return VFS.instance = vfs;
8286
}
8387

@@ -98,7 +102,9 @@ protected static Class<?> getClass(String className) {
98102
return Thread.currentThread().getContextClassLoader().loadClass(className);
99103
// return ReflectUtil.findClass(className);
100104
} catch (ClassNotFoundException e) {
101-
log.debug("Class not found: " + className);
105+
if (log.isDebugEnabled()) {
106+
log.debug("Class not found: " + className);
107+
}
102108
return null;
103109
}
104110
}

src/main/java/org/apache/ibatis/logging/LogFactory.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,9 @@ private static void setImplementation(Class<? extends Log> implClass) {
125125
try {
126126
Constructor<? extends Log> candidate = implClass.getConstructor(new Class[] { String.class });
127127
Log log = candidate.newInstance(new Object[] { LogFactory.class.getName() });
128-
log.debug("Logging initialized using '" + implClass + "' adapter.");
128+
if (log.isDebugEnabled()) {
129+
log.debug("Logging initialized using '" + implClass + "' adapter.");
130+
}
129131
logConstructor = candidate;
130132
} catch (Throwable t) {
131133
throw new LogException("Error setting Log implementation. Cause: " + t, t);

src/main/java/org/apache/ibatis/transaction/jdbc/JdbcTransaction.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,8 +122,10 @@ protected void resetAutoCommit() {
122122
connection.setAutoCommit(true);
123123
}
124124
} catch (SQLException e) {
125-
log.debug("Error resetting autocommit to true "
125+
if (log.isDebugEnabled()) {
126+
log.debug("Error resetting autocommit to true "
126127
+ "before closing the connection. Cause: " + e);
128+
}
127129
}
128130
}
129131

0 commit comments

Comments
 (0)