mirror of
https://github.com/DiscordSRV/Ascension.git
synced 2024-12-26 17:18:29 +01:00
Improve JavaLoggerImpl
This commit is contained in:
parent
54aadb9229
commit
ef978cb04f
@ -30,10 +30,7 @@ import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.logging.Filter;
|
||||
import java.util.logging.Handler;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.LogRecord;
|
||||
import java.util.logging.*;
|
||||
|
||||
public class JavaLoggerImpl implements Logger, LoggingBackend {
|
||||
|
||||
@ -66,17 +63,24 @@ public class JavaLoggerImpl implements Logger, LoggingBackend {
|
||||
@Override
|
||||
public void log(@Nullable String loggerName, @NotNull LogLevel level, @Nullable String message, @Nullable Throwable throwable) {
|
||||
Level logLevel = LEVELS_REVERSE.get(level);
|
||||
if (logLevel != null) {
|
||||
List<String> contents = new ArrayList<>(2);
|
||||
if (message != null) {
|
||||
contents.add(message);
|
||||
}
|
||||
if (throwable != null) {
|
||||
// Exceptions aren't always logged correctly by the logger itself
|
||||
contents.add(getStackTrace(throwable));
|
||||
}
|
||||
logger.log(logLevel, String.join("\n", contents));
|
||||
|
||||
boolean anythingAdded = false;
|
||||
StringBuilder stringBuilder = new StringBuilder(message != null ? message.length() : 0);
|
||||
|
||||
// Unknown level
|
||||
if (logLevel == null) {
|
||||
logLevel = Level.INFO;
|
||||
stringBuilder.append("[").append(level.name()).append("] ");
|
||||
anythingAdded = true;
|
||||
}
|
||||
|
||||
if (message != null) {
|
||||
stringBuilder.append(message);
|
||||
anythingAdded = true;
|
||||
}
|
||||
|
||||
String finalMessage = anythingAdded ? stringBuilder.toString() : null;
|
||||
logger.log(logLevel, finalMessage, throwable);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
Loading…
Reference in New Issue
Block a user