summaryrefslogtreecommitdiffstats
path: root/src/main/java
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java')
-rw-r--r--src/main/java/net/minecraft/server/DedicatedServer.java17
-rw-r--r--src/main/java/org/bukkit/craftbukkit/CraftServer.java3
-rw-r--r--src/main/java/org/bukkit/craftbukkit/util/ForwardLogHandler.java52
-rw-r--r--src/main/java/org/bukkit/craftbukkit/util/Log4jConverter.java68
-rw-r--r--src/main/java/org/bukkit/craftbukkit/util/TerminalConsoleWriterThread.java2
5 files changed, 63 insertions, 79 deletions
diff --git a/src/main/java/net/minecraft/server/DedicatedServer.java b/src/main/java/net/minecraft/server/DedicatedServer.java
index 03585b7a..1b116878 100644
--- a/src/main/java/net/minecraft/server/DedicatedServer.java
+++ b/src/main/java/net/minecraft/server/DedicatedServer.java
@@ -46,18 +46,19 @@ public class DedicatedServer extends MinecraftServer implements IMinecraftServer
threadcommandreader.setDaemon(true);
threadcommandreader.start();
- // CraftBukkit start - TODO: See if this needs fixing
- final org.apache.logging.log4j.core.Logger realLogger = ((org.apache.logging.log4j.core.Logger) LogManager.getRootLogger());
- for (org.apache.logging.log4j.core.Appender appender : realLogger.getAppenders().values()) {
- if (appender instanceof org.apache.logging.log4j.core.appender.ConsoleAppender) {
- realLogger.removeAppender(appender);
- }
+ // CraftBukkit start - TODO: handle command-line logging arguments
+ java.util.logging.Logger global = java.util.logging.Logger.getLogger("");
+ global.setUseParentHandlers(false);
+ for (java.util.logging.Handler handler : global.getHandlers()) {
+ global.removeHandler(handler);
}
+ global.addHandler(new org.bukkit.craftbukkit.util.ForwardLogHandler());
+ final org.apache.logging.log4j.core.Logger logger = ((org.apache.logging.log4j.core.Logger) LogManager.getRootLogger());
new Thread(new org.bukkit.craftbukkit.util.TerminalConsoleWriterThread(System.out, this.reader)).start();
- System.setOut(new PrintStream(new LoggerOutputStream(realLogger, Level.INFO), true));
- System.setErr(new PrintStream(new LoggerOutputStream(realLogger, Level.WARN), true));
+ System.setOut(new PrintStream(new LoggerOutputStream(logger, Level.INFO), true));
+ System.setErr(new PrintStream(new LoggerOutputStream(logger, Level.WARN), true));
// CraftBukkit end
h.info("Starting minecraft server version 1.7.2");
diff --git a/src/main/java/org/bukkit/craftbukkit/CraftServer.java b/src/main/java/org/bukkit/craftbukkit/CraftServer.java
index caa184ee..362b507b 100644
--- a/src/main/java/org/bukkit/craftbukkit/CraftServer.java
+++ b/src/main/java/org/bukkit/craftbukkit/CraftServer.java
@@ -94,7 +94,6 @@ import org.bukkit.craftbukkit.updater.AutoUpdater;
import org.bukkit.craftbukkit.updater.BukkitDLUpdaterService;
import org.bukkit.craftbukkit.util.CraftIconCache;
import org.bukkit.craftbukkit.util.DatFileFilter;
-import org.bukkit.craftbukkit.util.Log4jConverter;
import org.bukkit.craftbukkit.util.Versioning;
import org.bukkit.entity.Player;
import org.bukkit.event.inventory.InventoryType;
@@ -188,7 +187,7 @@ public final class CraftServer implements Server {
}
public CraftServer(MinecraftServer console, PlayerList playerList) {
- this.logger = Log4jConverter.createLogger();
+ this.logger = Logger.getLogger("Minecraft");
this.console = console;
this.playerList = (DedicatedPlayerList) playerList;
this.serverVersion = CraftServer.class.getPackage().getImplementationVersion();
diff --git a/src/main/java/org/bukkit/craftbukkit/util/ForwardLogHandler.java b/src/main/java/org/bukkit/craftbukkit/util/ForwardLogHandler.java
new file mode 100644
index 00000000..124c8ce5
--- /dev/null
+++ b/src/main/java/org/bukkit/craftbukkit/util/ForwardLogHandler.java
@@ -0,0 +1,52 @@
+package org.bukkit.craftbukkit.util;
+
+import org.apache.logging.log4j.LogManager;
+import org.apache.logging.log4j.Logger;
+
+import java.util.Map;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.logging.Handler;
+import java.util.logging.Level;
+import java.util.logging.LogRecord;
+
+public class ForwardLogHandler extends Handler {
+ private Map<String, Logger> cachedLoggers = new ConcurrentHashMap<String, Logger>();
+
+ private Logger getLogger(String name) {
+ Logger logger = cachedLoggers.get(name);
+ if (logger == null) {
+ logger = LogManager.getLogger(name);
+ cachedLoggers.put(name, logger);
+ }
+
+ return logger;
+ }
+
+ @Override
+ public void publish(LogRecord record) {
+ Logger logger = getLogger(record.getLoggerName());
+ String message = record.getMessage();
+ Throwable exception = record.getThrown();
+ Level level = record.getLevel();
+
+ if (level == Level.SEVERE) {
+ logger.error(message, exception);
+ } else if (level == Level.WARNING) {
+ logger.warn(message, exception);
+ } else if (level == Level.INFO) {
+ logger.info(message, exception);
+ } else if (level == Level.CONFIG) {
+ logger.debug(message, exception);
+ } else {
+ logger.trace(message, exception);
+ }
+ }
+
+ @Override
+ public void flush() {
+ }
+
+ @Override
+ public void close() throws SecurityException {
+ }
+}
diff --git a/src/main/java/org/bukkit/craftbukkit/util/Log4jConverter.java b/src/main/java/org/bukkit/craftbukkit/util/Log4jConverter.java
deleted file mode 100644
index fbaf51a7..00000000
--- a/src/main/java/org/bukkit/craftbukkit/util/Log4jConverter.java
+++ /dev/null
@@ -1,68 +0,0 @@
-package org.bukkit.craftbukkit.util;
-
-import java.util.EnumMap;
-import java.util.HashMap;
-import java.util.Map;
-import java.util.logging.Handler;
-import java.util.logging.Level;
-import java.util.logging.LogRecord;
-import java.util.logging.Logger;
-
-public class Log4jConverter {
-
- private static final Map<Level, org.apache.logging.log4j.Level> JULTOLOG4J = new HashMap<Level, org.apache.logging.log4j.Level>();
- private static final Map<org.apache.logging.log4j.Level, Level> LOG4JTOJUL = new EnumMap<org.apache.logging.log4j.Level, Level>(org.apache.logging.log4j.Level.class);
- static {
- JULTOLOG4J.put(Level.ALL, org.apache.logging.log4j.Level.ALL);
- JULTOLOG4J.put(Level.FINEST, org.apache.logging.log4j.Level.TRACE);
- JULTOLOG4J.put(Level.FINER, org.apache.logging.log4j.Level.TRACE);
- JULTOLOG4J.put(Level.FINE, org.apache.logging.log4j.Level.TRACE);
- JULTOLOG4J.put(Level.INFO, org.apache.logging.log4j.Level.INFO);
- JULTOLOG4J.put(Level.CONFIG, org.apache.logging.log4j.Level.INFO);
- JULTOLOG4J.put(Level.WARNING, org.apache.logging.log4j.Level.WARN);
- JULTOLOG4J.put(Level.SEVERE, org.apache.logging.log4j.Level.ERROR);
- JULTOLOG4J.put(Level.OFF, org.apache.logging.log4j.Level.OFF);
- LOG4JTOJUL.put(org.apache.logging.log4j.Level.ALL, Level.ALL);
- LOG4JTOJUL.put(org.apache.logging.log4j.Level.TRACE, Level.FINE);
- LOG4JTOJUL.put(org.apache.logging.log4j.Level.INFO, Level.INFO);
- LOG4JTOJUL.put(org.apache.logging.log4j.Level.DEBUG, Level.INFO);
- LOG4JTOJUL.put(org.apache.logging.log4j.Level.WARN, Level.WARNING);
- LOG4JTOJUL.put(org.apache.logging.log4j.Level.ERROR, Level.SEVERE);
- LOG4JTOJUL.put(org.apache.logging.log4j.Level.FATAL, Level.SEVERE);
- LOG4JTOJUL.put(org.apache.logging.log4j.Level.OFF, Level.OFF);
- }
-
- public static org.apache.logging.log4j.Level getLog4jLevel(Level level) {
- org.apache.logging.log4j.Level log4jLevel = JULTOLOG4J.get(level);
- return log4jLevel == null ? org.apache.logging.log4j.Level.INFO : log4jLevel;
- }
-
- public static Level getJULLevel(org.apache.logging.log4j.Level level) {
- return LOG4JTOJUL.get(level);
- }
-
- public static Logger createLogger() {
- final Logger logger = Logger.getLogger("Minecraft");
- // Grab a logger. It doesn't really matter which, so long as it is within net.minecraft.server.
- final org.apache.logging.log4j.core.Logger log4j = (org.apache.logging.log4j.core.Logger) org.apache.logging.log4j.LogManager.getLogger("net.minecraft.server.DedicatedServer");
- logger.setUseParentHandlers(false);
- // Add a handler to our Bukkit Logger so that messages logged to it are sent to log4j.
- Handler log4jHandler = new Handler() {
- @Override
- public void close() throws SecurityException {
- }
-
- @Override
- public void flush() {
- }
-
- @Override
- public void publish(LogRecord record) {
- log4j.log(Log4jConverter.getLog4jLevel(record.getLevel()), record.getMessage());
-
- }
- };
- logger.addHandler(log4jHandler);
- return logger;
- }
-}
diff --git a/src/main/java/org/bukkit/craftbukkit/util/TerminalConsoleWriterThread.java b/src/main/java/org/bukkit/craftbukkit/util/TerminalConsoleWriterThread.java
index e8ace741..0bdfde6d 100644
--- a/src/main/java/org/bukkit/craftbukkit/util/TerminalConsoleWriterThread.java
+++ b/src/main/java/org/bukkit/craftbukkit/util/TerminalConsoleWriterThread.java
@@ -22,7 +22,7 @@ public class TerminalConsoleWriterThread implements Runnable {
// Using name from log4j config in vanilla jar
while (true) {
- message = QueueLogAppender.getNextLogEvent("ServerGuiConsole");
+ message = QueueLogAppender.getNextLogEvent("TerminalConsole");
if (message == null) {
continue;
}