mirror of
https://github.com/PaperMC/Paper.git
synced 2024-12-29 15:49:00 +01:00
Redirect System.out and System.err to a Logger
By: Dinnerbone <dinnerbone@dinnerbone.com>
This commit is contained in:
parent
d24be8c986
commit
4389934bb8
2 changed files with 36 additions and 0 deletions
|
@ -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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in a new issue