Skip to content

Commit

Permalink
Merge pull request ronmamo#183 from sschuberth/logging-improvements
Browse files Browse the repository at this point in the history
Logging improvements
  • Loading branch information
ronmamo authored Nov 11, 2017
2 parents cd0f936 + 82b5dbc commit 8330768
Showing 2 changed files with 16 additions and 6 deletions.
18 changes: 12 additions & 6 deletions src/main/java/org/reflections/Reflections.java
Original file line number Diff line number Diff line change
@@ -180,8 +180,8 @@ protected void scan() {
return;
}

if (log != null && log.isDebugEnabled()) {
log.debug("going to scan these urls:\n" + Joiner.on("\n").join(configuration.getUrls()));
if (log != null) {
log.debug("going to scan these urls:\n{}", Joiner.on("\n").join(configuration.getUrls()));
}

long time = System.currentTimeMillis();
@@ -194,7 +194,9 @@ protected void scan() {
if (executorService != null) {
futures.add(executorService.submit(new Runnable() {
public void run() {
if (log != null && log.isDebugEnabled()) log.debug("[" + Thread.currentThread().toString() + "] scanning " + url);
if (log != null) {
log.debug("[{}] scanning {}", Thread.currentThread().toString(), url);
}
scan(url);
}
}));
@@ -203,7 +205,9 @@ public void run() {
}
scannedUrls++;
} catch (ReflectionsException e) {
if (log != null && log.isWarnEnabled()) log.warn("could not create Vfs.Dir from url. ignoring the exception and continuing", e);
if (log != null) {
log.warn("could not create Vfs.Dir from url. ignoring the exception and continuing", e);
}
}
}

@@ -253,8 +257,10 @@ protected void scan(URL url) {
classObject = scanner.scan(file, classObject);
}
} catch (Exception e) {
if (log != null && log.isDebugEnabled())
log.debug("could not scan file " + file.getRelativePath() + " in url " + url.toExternalForm() + " with scanner " + scanner.getClass().getSimpleName(), e);
if (log != null) {
// SLF4J will filter out Throwables from the format string arguments.
log.debug("could not scan file {} in url {} with scanner {}", file.getRelativePath(), url.toExternalForm(), scanner.getClass().getSimpleName(), e);
}
}
}
}
4 changes: 4 additions & 0 deletions src/main/java/org/reflections/util/Utils.java
Original file line number Diff line number Diff line change
@@ -152,6 +152,10 @@ public static void close(InputStream closeable) {
@Nullable
public static Logger findLogger(Class<?> aClass) {
try {
// This is to check whether an optional SLF4J binding is available. While SLF4J recommends that libraries
// "should not declare a dependency on any SLF4J binding but only depend on slf4j-api", doing so forces
// users of the library to either add a binding to the classpath (even if just slf4j-nop) or to set the
// "slf4j.suppressInitError" system property in order to avoid the warning, which both is inconvenient.
Class.forName("org.slf4j.impl.StaticLoggerBinder");
return LoggerFactory.getLogger(aClass);
} catch (Throwable e) {

0 comments on commit 8330768

Please sign in to comment.