Redirect System.out and System.err to a Logger

By: Dinnerbone <dinnerbone@dinnerbone.com>
This commit is contained in:
CraftBukkit/Spigot 2011-02-20 01:53:06 +00:00
parent d24be8c986
commit 4389934bb8
2 changed files with 36 additions and 0 deletions

View file

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

View file

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