diff --git a/src/main/java/net/dv8tion/jda/internal/utils/JDALogger.java b/src/main/java/net/dv8tion/jda/internal/utils/JDALogger.java index cbea27a869..79be0a20ca 100644 --- a/src/main/java/net/dv8tion/jda/internal/utils/JDALogger.java +++ b/src/main/java/net/dv8tion/jda/internal/utils/JDALogger.java @@ -19,11 +19,12 @@ import org.apache.commons.collections4.map.CaseInsensitiveMap; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import org.slf4j.helpers.NOPLoggerFactory; +import org.slf4j.spi.SLF4JServiceProvider; import java.io.PrintWriter; import java.io.StringWriter; import java.util.Map; +import java.util.ServiceLoader; /** * This class serves as a LoggerFactory for JDA's internals. @@ -31,21 +32,25 @@ * or an instance of a custom {@link FallbackLogger}. *
* It also has the utility method {@link #getLazyString(LazyEvaluation)} which is used to lazily construct Strings for Logging.
+ *
+ * @see #setFallbackLoggerEnabled(boolean)
*/
public class JDALogger
{
/**
- * Marks whether a SLF4J StaticLoggerBinder
(pre 1.8.x) or
- * SLF4JServiceProvider
implementation (1.8.x+) was found. If false, JDA will use its fallback logger.
- *
This variable is initialized during static class initialization.
+ * The name of the system property, which controls whether the fallback logger is disabled.
*/
- public static final boolean SLF4J_ENABLED;
- private static boolean disableFallback;
+ public static final String DISABLE_FALLBACK_PROPERTY_NAME = "net.dv8tion.jda.disableFallbackLogger";
- static
- {
- SLF4J_ENABLED = !(LoggerFactory.getILoggerFactory() instanceof NOPLoggerFactory);
- }
+ /**
+ * Whether an implementation of {@link SLF4JServiceProvider}was found.
+ *
If false, JDA will use its fallback logger.
+ *
+ *
The fallback logger can be disabled with {@link #setFallbackLoggerEnabled(boolean)}
+ * or using the system property {@value #DISABLE_FALLBACK_PROPERTY_NAME}.
+ */
+ public static final boolean SLF4J_ENABLED = ServiceLoader.load(SLF4JServiceProvider.class).iterator().hasNext();
+ private static boolean disableFallback = Boolean.getBoolean(DISABLE_FALLBACK_PROPERTY_NAME);
private static final Map