From 4389934bb8f3dec52652171c396a0c13b7cb9e38 Mon Sep 17 00:00:00 2001 From: CraftBukkit/Spigot Date: Sun, 20 Feb 2011 01:53:06 +0000 Subject: [PATCH] Redirect System.out and System.err to a Logger By: Dinnerbone --- .../org/bukkit/craftbukkit/CraftServer.java | 4 +++ .../craftbukkit/LoggerOutputStream.java | 32 +++++++++++++++++++ 2 files changed, 36 insertions(+) create mode 100644 paper-server/src/main/java/org/bukkit/craftbukkit/LoggerOutputStream.java diff --git a/paper-server/src/main/java/org/bukkit/craftbukkit/CraftServer.java b/paper-server/src/main/java/org/bukkit/craftbukkit/CraftServer.java index 9d30b79ceb..6365b382d2 100644 --- a/paper-server/src/main/java/org/bukkit/craftbukkit/CraftServer.java +++ b/paper-server/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/paper-server/src/main/java/org/bukkit/craftbukkit/LoggerOutputStream.java b/paper-server/src/main/java/org/bukkit/craftbukkit/LoggerOutputStream.java new file mode 100644 index 0000000000..d2637ad8e1 --- /dev/null +++ b/paper-server/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); + } + } + } +}