diff --git a/src/main/java/net/dv8tion/jda/internal/handle/GuildBanHandler.java b/src/main/java/net/dv8tion/jda/internal/handle/GuildBanHandler.java
index e8a5df4836..0da3c38d81 100644
--- a/src/main/java/net/dv8tion/jda/internal/handle/GuildBanHandler.java
+++ b/src/main/java/net/dv8tion/jda/internal/handle/GuildBanHandler.java
@@ -21,7 +21,6 @@
import net.dv8tion.jda.api.utils.data.DataObject;
import net.dv8tion.jda.internal.JDAImpl;
import net.dv8tion.jda.internal.entities.GuildImpl;
-import net.dv8tion.jda.internal.utils.JDALogger;
public class GuildBanHandler extends SocketHandler
{
@@ -45,7 +44,7 @@ protected Long handleInternally(DataObject content)
if (guild == null)
{
getJDA().getEventCache().cache(EventCache.Type.GUILD, id, responseNumber, allContent, this::handle);
- EventCache.LOG.debug("Received Guild Member {} event for a Guild not yet cached.", JDALogger.getLazyString(() -> banned ? "Ban" : "Unban"));
+ EventCache.LOG.debug("Received Guild Member {} event for a Guild not yet cached.", banned ? "Ban" : "Unban");
return null;
}
diff --git a/src/main/java/net/dv8tion/jda/internal/handle/MessageReactionHandler.java b/src/main/java/net/dv8tion/jda/internal/handle/MessageReactionHandler.java
index f6388e71bc..62c4e81e32 100644
--- a/src/main/java/net/dv8tion/jda/internal/handle/MessageReactionHandler.java
+++ b/src/main/java/net/dv8tion/jda/internal/handle/MessageReactionHandler.java
@@ -34,7 +34,6 @@
import net.dv8tion.jda.internal.entities.MemberImpl;
import net.dv8tion.jda.internal.entities.channel.concrete.PrivateChannelImpl;
import net.dv8tion.jda.internal.requests.WebSocketClient;
-import net.dv8tion.jda.internal.utils.JDALogger;
import java.util.List;
import java.util.Objects;
@@ -73,8 +72,7 @@ protected Long handleInternally(DataObject content)
if (emojiId == null && emojiName == null)
{
- WebSocketClient.LOG.debug("Received a reaction {} with no name nor id. json: {}",
- JDALogger.getLazyString(() -> add ? "add" : "remove"), content);
+ WebSocketClient.LOG.debug("Received a reaction {} with no name nor id. json: {}", add ? "add" : "remove", content);
return null;
}
final long guildId = content.getUnsignedLong("guild_id", 0);
diff --git a/src/main/java/net/dv8tion/jda/internal/utils/FallbackLogger.java b/src/main/java/net/dv8tion/jda/internal/utils/FallbackLogger.java
new file mode 100644
index 0000000000..1726930539
--- /dev/null
+++ b/src/main/java/net/dv8tion/jda/internal/utils/FallbackLogger.java
@@ -0,0 +1,81 @@
+/*
+ * Copyright 2015 Austin Keener, Michael Ritter, Florian Spieß, and the JDA contributors
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package net.dv8tion.jda.internal.utils;
+
+import org.slf4j.Marker;
+import org.slf4j.event.Level;
+import org.slf4j.helpers.FormattingTuple;
+import org.slf4j.helpers.LegacyAbstractLogger;
+import org.slf4j.helpers.MessageFormatter;
+
+import java.time.LocalDateTime;
+
+class FallbackLogger extends LegacyAbstractLogger
+{
+ private final String name;
+
+ public FallbackLogger(String name)
+ {
+ this.name = name;
+ }
+
+ @Override
+ protected String getFullyQualifiedCallerName()
+ {
+ return null;
+ }
+
+ @Override
+ protected void handleNormalizedLoggingCall(Level level, Marker marker, String messagePattern, Object[] arguments, Throwable throwable)
+ {
+ LocalDateTime now = LocalDateTime.now();
+ FormattingTuple result = MessageFormatter.arrayFormat(messagePattern, arguments);
+ System.err.printf("%1$tF %1$tT [%2$s] [%3$s] %4$s%n", now, name, level, result.getMessage());
+ if (throwable != null)
+ throwable.printStackTrace(System.err);
+ }
+
+ @Override
+ public boolean isTraceEnabled()
+ {
+ return false;
+ }
+
+ @Override
+ public boolean isDebugEnabled()
+ {
+ return false;
+ }
+
+ @Override
+ public boolean isInfoEnabled()
+ {
+ return true;
+ }
+
+ @Override
+ public boolean isWarnEnabled()
+ {
+ return true;
+ }
+
+ @Override
+ public boolean isErrorEnabled()
+ {
+ return true;
+ }
+}
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 1fe5cedb4c..cf842eb0ca 100644
--- a/src/main/java/net/dv8tion/jda/internal/utils/JDALogger.java
+++ b/src/main/java/net/dv8tion/jda/internal/utils/JDALogger.java
@@ -28,7 +28,7 @@
/**
* This class serves as a LoggerFactory for JDA's internals.
*
It will either return a Logger from a SLF4J implementation via {@link org.slf4j.LoggerFactory} if present,
- * or an instance of a custom {@link SimpleLogger} (From slf4j-simple).
+ * 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. */ @@ -83,7 +83,7 @@ private JDALogger() {} * Will get the {@link org.slf4j.Logger} with the given log-name * or create and cache a fallback logger if there is no SLF4J implementation present. *
- * The fallback logger will be an instance of a slightly modified version of SLF4Js SimpleLogger. + * The fallback logger uses a constant logging configuration and prints directly to {@link System#err}. * * @param name * The name of the Logger @@ -96,7 +96,7 @@ public static Logger getLog(String name) { if (SLF4J_ENABLED) return LoggerFactory.getLogger(name); - return LOGS.computeIfAbsent(name, SimpleLogger::new); + return LOGS.computeIfAbsent(name, FallbackLogger::new); } } @@ -104,7 +104,7 @@ public static Logger getLog(String name) * Will get the {@link org.slf4j.Logger} for the given Class * or create and cache a fallback logger if there is no SLF4J implementation present. *
- * The fallback logger will be an instance of a slightly modified version of SLF4Js SimpleLogger.
+ * The fallback logger uses a constant logging configuration and prints directly to {@link System#err}.
*
* @param clazz
* The class used for the Logger name
@@ -117,7 +117,7 @@ public static Logger getLog(Class> clazz)
{
if (SLF4J_ENABLED)
return LoggerFactory.getLogger(clazz);
- return LOGS.computeIfAbsent(clazz.getName(), (n) -> new SimpleLogger(clazz.getSimpleName()));
+ return LOGS.computeIfAbsent(clazz.getName(), (n) -> new FallbackLogger(clazz.getSimpleName()));
}
}
@@ -144,7 +144,7 @@ public String toString()
{
StringWriter sw = new StringWriter();
ex.printStackTrace(new PrintWriter(sw));
- return "Error while evaluating lazy String... " + sw.toString();
+ return "Error while evaluating lazy String... " + sw;
}
}
};
diff --git a/src/main/java/net/dv8tion/jda/internal/utils/SimpleLogger.java b/src/main/java/net/dv8tion/jda/internal/utils/SimpleLogger.java
deleted file mode 100644
index 44edb1e3d0..0000000000
--- a/src/main/java/net/dv8tion/jda/internal/utils/SimpleLogger.java
+++ /dev/null
@@ -1,438 +0,0 @@
-/*
- * Copyright 2015 Austin Keener, Michael Ritter, Florian Spieß, and the JDA contributors
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package net.dv8tion.jda.internal.utils;
-
-import org.slf4j.helpers.FormattingTuple;
-import org.slf4j.helpers.MarkerIgnoringBase;
-import org.slf4j.helpers.MessageFormatter;
-import org.slf4j.helpers.Util;
-import org.slf4j.spi.LocationAwareLogger;
-
-import java.io.FileNotFoundException;
-import java.io.FileOutputStream;
-import java.io.InputStream;
-import java.io.PrintStream;
-import java.security.AccessController;
-import java.security.PrivilegedAction;
-import java.text.DateFormat;
-import java.text.SimpleDateFormat;
-import java.util.Date;
-import java.util.Properties;
-
-class SimpleLogger extends MarkerIgnoringBase {
-
- private static final long serialVersionUID = -632788891211436180L;
- private static final String CONFIGURATION_FILE = "Logger.properties";
-
- private static long START_TIME = System.currentTimeMillis();
- private static final Properties SIMPLE_LOGGER_PROPS = new Properties();
-
- private static final int LOG_LEVEL_TRACE = LocationAwareLogger.TRACE_INT;
- private static final int LOG_LEVEL_DEBUG = LocationAwareLogger.DEBUG_INT;
- private static final int LOG_LEVEL_INFO = LocationAwareLogger.INFO_INT;
- private static final int LOG_LEVEL_WARN = LocationAwareLogger.WARN_INT;
- private static final int LOG_LEVEL_ERROR = LocationAwareLogger.ERROR_INT;
-
- private static boolean INITIALIZED = false;
-
- private static int DEFAULT_LOG_LEVEL = LOG_LEVEL_INFO;
- private static boolean SHOW_DATE_TIME = false;
- private static String DATE_TIME_FORMAT_STR = null;
- private static DateFormat DATE_FORMATTER = null;
- private static boolean SHOW_THREAD_NAME = true;
- private static boolean SHOW_LOG_NAME = true;
- private static boolean SHOW_SHORT_LOG_NAME = false;
- private static String LOG_FILE = "System.err";
- private static PrintStream TARGET_STREAM = null;
- private static boolean LEVEL_IN_BRACKETS = false;
- private static String WARN_LEVEL_STRING = "WARN";
-
- public static final String SYSTEM_PREFIX = "org.slf4j.Logger.";
-
- public static final String DEFAULT_LOG_LEVEL_KEY = SYSTEM_PREFIX + "defaultLogLevel";
- public static final String SHOW_DATE_TIME_KEY = SYSTEM_PREFIX + "showDateTime";
- public static final String DATE_TIME_FORMAT_KEY = SYSTEM_PREFIX + "dateTimeFormat";
- public static final String SHOW_THREAD_NAME_KEY = SYSTEM_PREFIX + "showThreadName";
- public static final String SHOW_LOG_NAME_KEY = SYSTEM_PREFIX + "showLogName";
- public static final String SHOW_SHORT_LOG_NAME_KEY = SYSTEM_PREFIX + "showShortLogName";
- public static final String LOG_FILE_KEY = SYSTEM_PREFIX + "logFile";
- public static final String LEVEL_IN_BRACKETS_KEY = SYSTEM_PREFIX + "levelInBrackets";
- public static final String WARN_LEVEL_STRING_KEY = SYSTEM_PREFIX + "warnLevelString";
-
- public static final String LOG_KEY_PREFIX = SYSTEM_PREFIX + "log.";
-
- private static String getStringProperty(String name) {
- String prop = null;
- try {
- prop = System.getProperty(name);
- } catch (SecurityException e) {
- ; // Ignore
- }
- return (prop == null) ? SIMPLE_LOGGER_PROPS.getProperty(name) : prop;
- }
-
- private static String getStringProperty(String name, String defaultValue) {
- String prop = getStringProperty(name);
- return (prop == null) ? defaultValue : prop;
- }
-
- private static boolean getBooleanProperty(String name, boolean defaultValue) {
- String prop = getStringProperty(name);
- return (prop == null) ? defaultValue : "true".equalsIgnoreCase(prop);
- }
-
- static void init() {
- INITIALIZED = true;
- loadProperties();
-
- String defaultLogLevelString = getStringProperty(DEFAULT_LOG_LEVEL_KEY, null);
- if (defaultLogLevelString != null)
- DEFAULT_LOG_LEVEL = stringToLevel(defaultLogLevelString);
-
- SHOW_LOG_NAME = getBooleanProperty(SHOW_LOG_NAME_KEY, SHOW_LOG_NAME);
- SHOW_SHORT_LOG_NAME = getBooleanProperty(SHOW_SHORT_LOG_NAME_KEY, SHOW_SHORT_LOG_NAME);
- SHOW_DATE_TIME = getBooleanProperty(SHOW_DATE_TIME_KEY, SHOW_DATE_TIME);
- SHOW_THREAD_NAME = getBooleanProperty(SHOW_THREAD_NAME_KEY, SHOW_THREAD_NAME);
- DATE_TIME_FORMAT_STR = getStringProperty(DATE_TIME_FORMAT_KEY, DATE_TIME_FORMAT_STR);
- LEVEL_IN_BRACKETS = getBooleanProperty(LEVEL_IN_BRACKETS_KEY, LEVEL_IN_BRACKETS);
- WARN_LEVEL_STRING = getStringProperty(WARN_LEVEL_STRING_KEY, WARN_LEVEL_STRING);
-
- LOG_FILE = getStringProperty(LOG_FILE_KEY, LOG_FILE);
- TARGET_STREAM = computeTargetStream(LOG_FILE);
-
- if (DATE_TIME_FORMAT_STR != null) {
- try {
- DATE_FORMATTER = new SimpleDateFormat(DATE_TIME_FORMAT_STR);
- } catch (IllegalArgumentException e) {
- Util.report("Bad date format in " + CONFIGURATION_FILE + "; will output relative time", e);
- }
- }
- }
-
- private static PrintStream computeTargetStream(String logFile) {
- if ("System.err".equalsIgnoreCase(logFile))
- return System.err;
- else if ("System.out".equalsIgnoreCase(logFile)) {
- return System.out;
- } else {
- try {
- FileOutputStream fos = new FileOutputStream(logFile);
- PrintStream printStream = new PrintStream(fos);
- return printStream;
- } catch (FileNotFoundException e) {
- Util.report("Could not open [" + logFile + "]. Defaulting to System.err", e);
- return System.err;
- }
- }
- }
-
- private static void loadProperties() {
- // Add props from the resource Logger.properties
- InputStream in = AccessController.doPrivileged(new PrivilegedAction