13
0
geforkt von Mirrors/Paper

Redirect System.out and System.err to a Logger

Dieser Commit ist enthalten in:
Dinnerbone 2011-02-20 01:53:06 +00:00
Ursprung a6b3965672
Commit 264b5c331d
3 geänderte Dateien mit 44 neuen und 0 gelöschten Zeilen

Datei anzeigen

@ -3,6 +3,7 @@ package net.minecraft.server;
import java.awt.GraphicsEnvironment; import java.awt.GraphicsEnvironment;
import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.io.PrintStream;
import java.net.InetAddress; import java.net.InetAddress;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collections; import java.util.Collections;
@ -17,6 +18,7 @@ import java.net.UnknownHostException;
import joptsimple.OptionSet; import joptsimple.OptionSet;
import org.bukkit.command.ConsoleCommandSender; import org.bukkit.command.ConsoleCommandSender;
import org.bukkit.craftbukkit.CraftServer; import org.bukkit.craftbukkit.CraftServer;
import org.bukkit.craftbukkit.LoggerOutputStream;
import org.bukkit.craftbukkit.scheduler.CraftScheduler; import org.bukkit.craftbukkit.scheduler.CraftScheduler;
import org.bukkit.event.Event; import org.bukkit.event.Event;
import org.bukkit.event.world.WorldEvent; import org.bukkit.event.world.WorldEvent;
@ -61,6 +63,12 @@ public class MinecraftServer implements ICommandListener, Runnable {
threadcommandreader.setDaemon(true); threadcommandreader.setDaemon(true);
threadcommandreader.start(); threadcommandreader.start();
ConsoleLogManager.a(); 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"); a.info("Starting minecraft server version Beta 1.2_01");
if (Runtime.getRuntime().maxMemory() / 1024L / 1024L < 512L) { if (Runtime.getRuntime().maxMemory() / 1024L / 1024L < 512L) {
a.warning("**** NOT ENOUGH RAM!"); a.warning("**** NOT ENOUGH RAM!");

Datei anzeigen

@ -260,4 +260,8 @@ public final class CraftServer implements Server {
pluginManager.callEvent(new WorldEvent(Type.WORLD_LOADED, world)); pluginManager.callEvent(new WorldEvent(Type.WORLD_LOADED, world));
} }
public Logger getLogger() {
return MinecraftServer.a;
}
} }

Datei anzeigen

@ -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);
}
}
}
}