Skip to content

Commit c117ea2

Browse files
Do not do string concatenation on logger, except where guarded with i… (#7)
* Do not do string concatenation on logger, except where guarded with isTraceEnabled * More string concatenation removals
1 parent b8781be commit c117ea2

3 files changed

Lines changed: 156 additions & 31 deletions

File tree

src/main/java/com/teragrep/rlo_12/DirectoryEventWatcher.java

Lines changed: 28 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,12 @@ public void watch() throws IOException, InterruptedException {
212212
WatchEvent<Path> ev = (WatchEvent<Path>) event;
213213
Path filename = ev.context();
214214

215-
LOGGER.trace("ev <" + kind + "> on <[" + directory.resolve(filename) + "]>");
215+
if(LOGGER.isTraceEnabled()) {
216+
LOGGER.trace(
217+
"ev <{}> on <[{}]>",
218+
kind,
219+
directory.resolve(filename));
220+
}
216221

217222
if (kind == ENTRY_DELETE) {
218223
// remove file from known files set
@@ -251,23 +256,26 @@ private class ScavengingFileVisitor implements FileVisitor<Path> {
251256

252257
@Override
253258
public FileVisitResult visitFile(Path path, BasicFileAttributes attrs) throws IOException {
254-
LOGGER.trace("visitFile <[" + path + "]>");
259+
LOGGER.trace("visitFile <[{}]>", path);
255260

256261
if (path.toFile().isDirectory()) {
257262
if (path.toAbsolutePath().equals(initialDirectory) || recursive) {
258263
if (!path.toFile().canRead()) {
259264
// non-readables are skipped
260-
LOGGER.warn("Directory <[" + path.toAbsolutePath() + "]> is not readable, skipping.");
265+
if(LOGGER.isWarnEnabled()) {
266+
LOGGER.warn("Directory <[{}]> is not readable, skipping.", path.toAbsolutePath());
267+
}
261268
return FileVisitResult.SKIP_SUBTREE;
262269
}
263270
register(path);
264271
} else {
265-
LOGGER.trace("Path skipped <[" + path.toAbsolutePath() + "]> due to non-recursive processing");
266-
272+
if(LOGGER.isTraceEnabled()) {
273+
LOGGER.trace("Path skipped <[{}]> due to non-recursive processing", path.toAbsolutePath());
274+
}
267275
}
268276
} else if (path.toFile().isFile()) {
269277
if (filePatternMatcher.reset(path.getFileName().toString()).matches()) {
270-
LOGGER.trace("visitFile filePatternMatcher matches <[" + path + "]> adding!");
278+
LOGGER.trace("visitFile filePatternMatcher matches <[{}]> adding!", path);
271279
try {
272280
transferQueue.transfer(new MonitoredFile(path.toAbsolutePath(), MonitoredFile.Status.FILE_MODIFIED));
273281

@@ -286,15 +294,15 @@ public FileVisitResult visitFile(Path path, BasicFileAttributes attrs) throws IO
286294

287295
@Override
288296
public FileVisitResult visitFileFailed(Path path, IOException exc) {
289-
LOGGER.warn("visitFileFailed <[" + path + "]> is not accessible, skipping due to: " + exc);
297+
LOGGER.warn("visitFileFailed <[{}]> is not accessible, skipping due to:", path, exc);
290298
return FileVisitResult.CONTINUE;
291299
}
292300

293301
@Override
294302
public FileVisitResult postVisitDirectory(Path dir, IOException exc) throws IOException {
295-
LOGGER.trace("postVisitDirectory <[" + dir + "]>");
303+
LOGGER.trace("postVisitDirectory <[{}]>", dir);
296304
if (exc != null) {
297-
LOGGER.warn("Directory <[" + dir + "]> caused: " + exc);
305+
LOGGER.warn("Directory <[{}]> caused:", dir, exc);
298306
return FileVisitResult.SKIP_SUBTREE;
299307
} else {
300308
return FileVisitResult.CONTINUE;
@@ -303,24 +311,30 @@ public FileVisitResult postVisitDirectory(Path dir, IOException exc) throws IOEx
303311

304312
@Override
305313
public FileVisitResult preVisitDirectory(Path dir, BasicFileAttributes attrs) throws IOException {
306-
LOGGER.trace("preVisitDirectory <[" + dir.toAbsolutePath() + "]>");
314+
if(LOGGER.isTraceEnabled()) {
315+
LOGGER.trace("preVisitDirectory <[{}]>", dir.toAbsolutePath());
316+
}
307317
if (dir.toAbsolutePath().equals(initialDirectory) || recursive) {
308318
if (!dir.toFile().canRead()) {
309319
// non-readables are skipped
310-
LOGGER.warn("Directory <[" + dir.toAbsolutePath() + "]> is not readable, skipping.");
320+
if(LOGGER.isWarnEnabled()) {
321+
LOGGER.warn("Directory <[{}]> is not readable, skipping.", dir.toAbsolutePath());
322+
}
311323
return FileVisitResult.SKIP_SUBTREE;
312324
}
313325
register(dir.toAbsolutePath());
314326
} else {
315-
LOGGER.trace("Directory skipped <[" + dir.toAbsolutePath() + "]> due to non-recursive processing");
327+
if(LOGGER.isTraceEnabled()) {
328+
LOGGER.trace("Directory skipped <[{}]> due to non-recursive processing", dir.toAbsolutePath());
329+
}
316330
}
317331
return FileVisitResult.CONTINUE;
318332
}
319333
}
320334

321335
private void register(Path directory) throws IOException {
322336
Path absolutePath = directory.toAbsolutePath();
323-
LOGGER.trace("register <[" + directory + "]> resolved to <[" + absolutePath + "]>");
337+
LOGGER.trace("register <[{}]> resolved to <[{}]>", directory, absolutePath);
324338

325339
// FIXME select proper watcher
326340
WatchKey key = absolutePath.register(directoryWatcher,
@@ -339,7 +353,7 @@ private void register(Path directory) throws IOException {
339353
New directory found, processing it
340354
*/
341355
if (!watchKeyPathMap.containsKey(key)) {
342-
LOGGER.trace("found unregistered directory <[" + directory + "]>");
356+
LOGGER.trace("found unregistered directory <[{}]>", directory);
343357
watchKeyPathMap.put(key, directory);
344358

345359
Files.walkFileTree(

0 commit comments

Comments
 (0)