diff --git a/src/main/java/org/reflections/Configuration.java b/src/main/java/org/reflections/Configuration.java index 37bf66fc..d5c99401 100644 --- a/src/main/java/org/reflections/Configuration.java +++ b/src/main/java/org/reflections/Configuration.java @@ -30,4 +30,9 @@ public interface Configuration { /** if true (default), expand super types after scanning, for super types that were not scanned. *

see {@link Reflections#expandSuperTypes(Map, Map)}*/ boolean shouldExpandSuperTypes(); + + /** if true (default), log the scanning process. + * @return true if logging is enabled, false otherwise + */ + boolean shouldLog(); } diff --git a/src/main/java/org/reflections/Reflections.java b/src/main/java/org/reflections/Reflections.java index a939c7bb..5fb8ea1d 100644 --- a/src/main/java/org/reflections/Reflections.java +++ b/src/main/java/org/reflections/Reflections.java @@ -186,13 +186,13 @@ protected Map>> scan() { if (entries != null) collect.get(scanner.index()).addAll(entries); } } catch (Exception e) { - if (log != null) log.debug("could not scan file {} with scanner {}", file.getRelativePath(), scanner.getClass().getSimpleName(), e); + if (log != null && configuration.shouldLog()) log.debug("could not scan file {} with scanner {}", file.getRelativePath(), scanner.getClass().getSimpleName(), e); } } } } } catch (Exception e) { - if (log != null) log.warn("could not create Vfs.Dir from url. ignoring the exception and continuing", e); + if (log != null && configuration.shouldLog()) log.warn("could not create Vfs.Dir from url. ignoring the exception and continuing", e); } }); @@ -206,7 +206,7 @@ protected Map>> scan() { Map.Entry::getKey, HashMap::new, Collectors.mapping(Map.Entry::getValue, Collectors.toSet()))))); - if (log != null) { + if (log != null && configuration.shouldLog()) { int keys = 0, values = 0; for (Map> map : storeMap.values()) { keys += map.size(); diff --git a/src/main/java/org/reflections/util/ConfigurationBuilder.java b/src/main/java/org/reflections/util/ConfigurationBuilder.java index 7bf5f9cd..4b039353 100644 --- a/src/main/java/org/reflections/util/ConfigurationBuilder.java +++ b/src/main/java/org/reflections/util/ConfigurationBuilder.java @@ -43,6 +43,7 @@ public class ConfigurationBuilder implements Configuration { private boolean isParallel = true; private ClassLoader[] classLoaders; private boolean expandSuperTypes = true; + private boolean shouldLog = true; public ConfigurationBuilder() { urls = new HashSet<>(); @@ -232,10 +233,20 @@ public boolean shouldExpandSuperTypes() { return expandSuperTypes; } + @Override + public boolean shouldLog() { + return shouldLog; + } + /** if set to true, Reflections will expand super types after scanning. *

see {@link org.reflections.Reflections#expandSuperTypes(Map, Map)} */ public ConfigurationBuilder setExpandSuperTypes(boolean expandSuperTypes) { this.expandSuperTypes = expandSuperTypes; return this; } + + public ConfigurationBuilder disableLogging() { + this.shouldLog = false; + return this; + } }