diff --git a/src/main/java/net/minecraft/server/MinecraftServer.java b/src/main/java/net/minecraft/server/MinecraftServer.java index 7cbbbefccc..6f16c45c3a 100644 --- a/src/main/java/net/minecraft/server/MinecraftServer.java +++ b/src/main/java/net/minecraft/server/MinecraftServer.java @@ -3,6 +3,7 @@ package net.minecraft.server; import java.awt.GraphicsEnvironment; import java.io.File; import java.io.IOException; +import java.io.PrintStream; import java.net.InetAddress; import java.util.ArrayList; import java.util.Collections; @@ -17,6 +18,7 @@ import java.net.UnknownHostException; import joptsimple.OptionSet; import org.bukkit.command.ConsoleCommandSender; import org.bukkit.craftbukkit.CraftServer; +import org.bukkit.craftbukkit.LoggerOutputStream; import org.bukkit.craftbukkit.scheduler.CraftScheduler; import org.bukkit.event.Event; import org.bukkit.event.world.WorldEvent; @@ -61,6 +63,12 @@ public class MinecraftServer implements ICommandListener, Runnable { threadcommandreader.setDaemon(true); threadcommandreader.start(); ConsoleLogManager.a(); + + // Craftbukkit start + System.setOut(new PrintStream(new LoggerOutputStream(a, Level.INFO), true)); + System.setErr(new PrintStream(new LoggerOutputStream(a, Level.SEVERE), true)); + // Craftbukkit end + a.info("Starting minecraft server version Beta 1.2_01"); if (Runtime.getRuntime().maxMemory() / 1024L / 1024L < 512L) { a.warning("**** NOT ENOUGH RAM!"); diff --git a/src/main/java/org/bukkit/craftbukkit/CraftServer.java b/src/main/java/org/bukkit/craftbukkit/CraftServer.java index 9d30b79ceb..6365b382d2 100644 --- a/src/main/java/org/bukkit/craftbukkit/CraftServer.java +++ b/src/main/java/org/bukkit/craftbukkit/CraftServer.java @@ -260,4 +260,8 @@ public final class CraftServer implements Server { pluginManager.callEvent(new WorldEvent(Type.WORLD_LOADED, world)); } + + public Logger getLogger() { + return MinecraftServer.a; + } } diff --git a/src/main/java/org/bukkit/craftbukkit/LoggerOutputStream.java b/src/main/java/org/bukkit/craftbukkit/LoggerOutputStream.java new file mode 100644 index 0000000000..d2637ad8e1 --- /dev/null +++ b/src/main/java/org/bukkit/craftbukkit/LoggerOutputStream.java @@ -0,0 +1,32 @@ + +package org.bukkit.craftbukkit; + +import java.io.ByteArrayOutputStream; +import java.io.IOException; +import java.util.logging.Level; +import java.util.logging.Logger; + +public class LoggerOutputStream extends ByteArrayOutputStream { + private final String separator = System.getProperty("line.separator"); + private final Logger logger; + private final Level level; + + public LoggerOutputStream(Logger logger, Level level) { + super(); + this.logger = logger; + this.level = level; + } + + @Override + public void flush() throws IOException { + synchronized (this) { + super.flush(); + String record = this.toString(); + super.reset(); + + if ((record.length() > 0) && (!record.equals(separator))) { + logger.logp(level, "", "", record); + } + } + } +}