mirror of
https://github.com/PaperMC/Paper.git
synced 2024-11-30 14:33:56 +01:00
Redirect System.out and System.err to a Logger
This commit is contained in:
parent
a6b3965672
commit
264b5c331d
@ -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!");
|
||||
|
@ -260,4 +260,8 @@ public final class CraftServer implements Server {
|
||||
|
||||
pluginManager.callEvent(new WorldEvent(Type.WORLD_LOADED, world));
|
||||
}
|
||||
|
||||
public Logger getLogger() {
|
||||
return MinecraftServer.a;
|
||||
}
|
||||
}
|
||||
|
32
src/main/java/org/bukkit/craftbukkit/LoggerOutputStream.java
Normal file
32
src/main/java/org/bukkit/craftbukkit/LoggerOutputStream.java
Normal 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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user