Skip to content

Commit 7544fba

Browse files
committed
Merge pull request #370 from kazuki43zoo/issues/369_isDebugEnabled
#369: Modify to use the Log#isDebugEnabled()
2 parents 0bf2d35 + 9ceedeb commit 7544fba

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
@@ -78,7 +78,9 @@ static Object crateProxy(Class<?> type, Callback callback, List<Class<?>> constr
7878
try {
7979
type.getDeclaredMethod(WRITE_REPLACE_METHOD);
8080
// ObjectOutputStream will call writeReplace of objects returned by writeReplace
81-
log.debug(WRITE_REPLACE_METHOD + " method was found on bean " + type + ", make sure it returns this");
81+
if (log.isDebugEnabled()) {
82+
log.debug(WRITE_REPLACE_METHOD + " method was found on bean " + type + ", make sure it returns this");
83+
}
8284
} catch (NoSuchMethodException e) {
8385
enhancer.setInterfaces(new Class[]{WriteReplaceInterface.class});
8486
} 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
@@ -78,7 +78,9 @@ static Object crateProxy(Class<?> type, MethodHandler callback, List<Class<?>> c
7878
try {
7979
type.getDeclaredMethod(WRITE_REPLACE_METHOD);
8080
// ObjectOutputStream will call writeReplace of objects returned by writeReplace
81-
log.debug(WRITE_REPLACE_METHOD + " method was found on bean " + type + ", make sure it returns this");
81+
if (log.isDebugEnabled()) {
82+
log.debug(WRITE_REPLACE_METHOD + " method was found on bean " + type + ", make sure it returns this");
83+
}
8284
} catch (NoSuchMethodException e) {
8385
enhancer.setInterfaces(new Class[]{WriteReplaceInterface.class});
8486
} 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
jarInput.close();
@@ -92,7 +98,9 @@ public List<String> list(URL url, String path) throws IOException {
9298
BufferedReader reader = new BufferedReader(new InputStreamReader(is));
9399
List<String> lines = new ArrayList<String>();
94100
for (String line; (line = reader.readLine()) != null;) {
95-
log.debug("Reader entry: " + line);
101+
if (log.isDebugEnabled()) {
102+
log.debug("Reader entry: " + line);
103+
}
96104
lines.add(line);
97105
if (getResources(path + "/" + line).isEmpty()) {
98106
lines.clear();
@@ -101,7 +109,9 @@ public List<String> list(URL url, String path) throws IOException {
101109
}
102110

103111
if (!lines.isEmpty()) {
104-
log.debug("Listing " + url);
112+
if (log.isDebugEnabled()) {
113+
log.debug("Listing " + url);
114+
}
105115
children.addAll(lines);
106116
}
107117
}
@@ -113,9 +123,13 @@ public List<String> list(URL url, String path) throws IOException {
113123
*/
114124
if ("file".equals(url.getProtocol())) {
115125
File file = new File(url.getFile());
116-
log.debug("Listing directory " + file.getAbsolutePath());
126+
if (log.isDebugEnabled()) {
127+
log.debug("Listing directory " + file.getAbsolutePath());
128+
}
117129
if (file.isDirectory()) {
118-
log.debug("Listing " + url);
130+
if (log.isDebugEnabled()) {
131+
log.debug("Listing " + url);
132+
}
119133
children = Arrays.asList(file.list());
120134
}
121135
}
@@ -182,7 +196,9 @@ protected List<String> listResources(JarInputStream jar, String path) throws IOE
182196

183197
// Check file name
184198
if (name.startsWith(path)) {
185-
log.debug("Found resource: " + name);
199+
if (log.isDebugEnabled()) {
200+
log.debug("Found resource: " + name);
201+
}
186202
// Trim leading slash
187203
resources.add(name.substring(1));
188204
}
@@ -202,13 +218,17 @@ protected List<String> listResources(JarInputStream jar, String path) throws IOE
202218
* @throws MalformedURLException
203219
*/
204220
protected URL findJarForResource(URL url) throws MalformedURLException {
205-
log.debug("Find JAR URL: " + url);
221+
if (log.isDebugEnabled()) {
222+
log.debug("Find JAR URL: " + url);
223+
}
206224

207225
// If the file part of the URL is itself a URL, then that URL probably points to the JAR
208226
try {
209227
for (;;) {
210228
url = new URL(url.getFile());
211-
log.debug("Inner URL: " + url);
229+
if (log.isDebugEnabled()) {
230+
log.debug("Inner URL: " + url);
231+
}
212232
}
213233
} catch (MalformedURLException e) {
214234
// This will happen at some point and serves as a break in the loop
@@ -219,10 +239,14 @@ protected URL findJarForResource(URL url) throws MalformedURLException {
219239
int index = jarUrl.lastIndexOf(".jar");
220240
if (index >= 0) {
221241
jarUrl.setLength(index + 4);
222-
log.debug("Extracted JAR URL: " + jarUrl);
242+
if (log.isDebugEnabled()) {
243+
log.debug("Extracted JAR URL: " + jarUrl);
244+
}
223245
}
224246
else {
225-
log.debug("Not a JAR: " + jarUrl);
247+
if (log.isDebugEnabled()) {
248+
log.debug("Not a JAR: " + jarUrl);
249+
}
226250
return null;
227251
}
228252

@@ -234,7 +258,9 @@ protected URL findJarForResource(URL url) throws MalformedURLException {
234258
}
235259
else {
236260
// WebLogic fix: check if the URL's file exists in the filesystem.
237-
log.debug("Not a JAR: " + jarUrl);
261+
if (log.isDebugEnabled()) {
262+
log.debug("Not a JAR: " + jarUrl);
263+
}
238264
jarUrl.replace(0, jarUrl.length(), testUrl.getFile());
239265
File file = new File(jarUrl.toString());
240266

@@ -248,7 +274,9 @@ protected URL findJarForResource(URL url) throws MalformedURLException {
248274
}
249275

250276
if (file.exists()) {
251-
log.debug("Trying real file: " + file.getAbsolutePath());
277+
if (log.isDebugEnabled()) {
278+
log.debug("Trying real file: " + file.getAbsolutePath());
279+
}
252280
testUrl = file.toURI().toURL();
253281
if (isJar(testUrl)) {
254282
return testUrl;
@@ -259,7 +287,9 @@ protected URL findJarForResource(URL url) throws MalformedURLException {
259287
log.warn("Invalid JAR URL: " + jarUrl);
260288
}
261289

262-
log.debug("Not a JAR: " + jarUrl);
290+
if (log.isDebugEnabled()) {
291+
log.debug("Not a JAR: " + jarUrl);
292+
}
263293
return null;
264294
}
265295

@@ -296,7 +326,9 @@ protected boolean isJar(URL url, byte[] buffer) {
296326
is = url.openStream();
297327
is.read(buffer, 0, JAR_MAGIC.length);
298328
if (Arrays.equals(buffer, JAR_MAGIC)) {
299-
log.debug("Found JAR: " + url);
329+
if (log.isDebugEnabled()) {
330+
log.debug("Found JAR: " + url);
331+
}
300332
return true;
301333
}
302334
} 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
@@ -252,7 +252,9 @@ protected void addIfMatching(Test test, String fqn) {
252252
try {
253253
String externalName = fqn.substring(0, fqn.indexOf('.')).replace('/', '.');
254254
ClassLoader loader = getClassLoader();
255-
log.debug("Checking to see if class " + externalName + " matches criteria [" + test + "]");
255+
if (log.isDebugEnabled()) {
256+
log.debug("Checking to see if class " + externalName + " matches criteria [" + test + "]");
257+
}
256258

257259
Class<?> type = loader.loadClass(externalName);
258260
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
@@ -66,8 +66,10 @@ public static VFS getInstance() {
6666
try {
6767
vfs = impl.newInstance();
6868
if (vfs == null || !vfs.isValid()) {
69-
log.debug("VFS implementation " + impl.getName() +
69+
if (log.isDebugEnabled()) {
70+
log.debug("VFS implementation " + impl.getName() +
7071
" is not valid in this environment.");
72+
}
7173
}
7274
} catch (InstantiationException e) {
7375
log.error("Failed to instantiate " + impl, e);
@@ -78,7 +80,9 @@ public static VFS getInstance() {
7880
}
7981
}
8082

81-
log.debug("Using VFS adapter " + vfs.getClass().getName());
83+
if (log.isDebugEnabled()) {
84+
log.debug("Using VFS adapter " + vfs.getClass().getName());
85+
}
8286
VFS.instance = vfs;
8387
return VFS.instance;
8488
}
@@ -101,7 +105,9 @@ protected static Class<?> getClass(String className) {
101105
return Thread.currentThread().getContextClassLoader().loadClass(className);
102106
// return ReflectUtil.findClass(className);
103107
} catch (ClassNotFoundException e) {
104-
log.debug("Class not found: " + className);
108+
if (log.isDebugEnabled()) {
109+
log.debug("Class not found: " + className);
110+
}
105111
return null;
106112
}
107113
}

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,9 @@ private static void setImplementation(Class<? extends Log> implClass) {
131131
try {
132132
Constructor<? extends Log> candidate = implClass.getConstructor(new Class[] { String.class });
133133
Log log = candidate.newInstance(new Object[] { LogFactory.class.getName() });
134-
log.debug("Logging initialized using '" + implClass + "' adapter.");
134+
if (log.isDebugEnabled()) {
135+
log.debug("Logging initialized using '" + implClass + "' adapter.");
136+
}
135137
logConstructor = candidate;
136138
} catch (Throwable t) {
137139
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
@@ -126,8 +126,10 @@ protected void resetAutoCommit() {
126126
connection.setAutoCommit(true);
127127
}
128128
} catch (SQLException e) {
129-
log.debug("Error resetting autocommit to true "
129+
if (log.isDebugEnabled()) {
130+
log.debug("Error resetting autocommit to true "
130131
+ "before closing the connection. Cause: " + e);
132+
}
131133
}
132134
}
133135

0 commit comments

Comments
 (0)