Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rfb support and new JUL logging #159

Open
wants to merge 11 commits into
base: staging
Choose a base branch
from
8 changes: 8 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,10 @@ repositories {
name 'minecraft'
url 'https://libraries.minecraft.net/'
}
maven {
name 'gtnh'
url 'https://nexus.gtnewhorizons.com/repository/public/'
}
}

minecraft {
Expand All @@ -57,6 +61,7 @@ minecraft {
'https://github.com/juanmuscaria/maven/raw/master',
'https://maven.minecraftforge.net/',
'https://oss.sonatype.org/content/repositories/snapshots/',
'https://nexus.gtnewhorizons.com/repository/public/',
'https://libraries.minecraft.net/'
]
}
Expand All @@ -81,6 +86,9 @@ configurations {

dependencies {
// New java stuff
libraries('com.gtnewhorizons.retrofuturabootstrap:RetroFuturaBootstrap:1.0.7') {
exclude group: 'org.apache.logging.log4j'
}
libraries 'org.apache.commons:commons-lang3:3.12.0'
libraries 'org.apache.commons:commons-compress:1.21'
libraries 'org.ow2.asm:asm:9.5'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,12 @@
new ServerLaunchWrapper().run(args);
}

@@ -22,7 +25,7 @@
Class<?> launchwrapper = null;
try
{
- launchwrapper = Class.forName("net.minecraft.launchwrapper.Launch",true,getClass().getClassLoader());
+ launchwrapper = Class.forName("com.gtnewhorizons.retrofuturabootstrap.Main",true,getClass().getClassLoader());
Class.forName("org.objectweb.asm.Type",true,getClass().getClassLoader());
}
catch (Exception e)
Original file line number Diff line number Diff line change
Expand Up @@ -976,7 +976,7 @@
+ // Spigot Start
+ if (org.spigotmc.SpigotConfig.logCommands)
+ {
+ this.logger.info(event.getPlayer().getName() + " issued server command: " + event.getMessage()); // CraftBukkit
+ this.logger.info("{} issued server command: {}", event.getPlayer().getName(), event.getMessage()); // CraftBukkit
+ }
+
+ // Spigot end
Expand Down
66 changes: 9 additions & 57 deletions patches/net/minecraft/server/dedicated/DedicatedServer.java.patch
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@
{
private static final String __OBFID = "CL_00001787";
{
@@ -82,31 +100,102 @@
@@ -82,31 +100,54 @@
};
}

Expand Down Expand Up @@ -111,7 +111,7 @@
- DedicatedServer.this.addPendingCommand(s4, DedicatedServer.this);
+ if (useJline)
+ {
+ s = bufferedreader.readLine(">", null);
+ s = bufferedreader.readLine("", null);
+ }
+ else
+ {
Expand All @@ -135,59 +135,11 @@
};
thread.setDaemon(true);
thread.start();
+ // CraftBukkit start - TODO: handle command-line logging arguments
+ java.util.logging.Logger global = java.util.logging.Logger.getLogger("");
+ global.setUseParentHandlers(false);
+
+ for (java.util.logging.Handler handler : global.getHandlers())
+ {
+ global.removeHandler(handler);
+ }
+
+ global.addHandler(new ForwardLogHandler());
+
+ final org.apache.logging.log4j.core.Logger logger = ((org.apache.logging.log4j.core.Logger) LogManager.getRootLogger());
+
+ for (org.apache.logging.log4j.core.Appender appender : logger.getAppenders().values())
+ {
+ if (appender instanceof org.apache.logging.log4j.core.appender.ConsoleAppender)
+ {
+ logger.removeAppender(appender);
+ }
+ }
+
+ // Crucible start - go nuclear on all other loggers
+ try {
+ LoggerContext ctx = (LoggerContext) FMLRelaunchLog.log.ctx;
+ Field loggersField = LoggerContext.class.getDeclaredField("loggers");
+ loggersField.setAccessible(true);
+ @SuppressWarnings("unchecked")
+ ConcurrentMap<String, org.apache.logging.log4j.core.Logger> loggers =
+ (ConcurrentMap<String, org.apache.logging.log4j.core.Logger>) loggersField.get(ctx);
+ for (org.apache.logging.log4j.core.Logger loggerToHack : loggers.values()) {
+ for (org.apache.logging.log4j.core.Appender appender : loggerToHack.getAppenders().values())
+ {
+ if (appender instanceof org.apache.logging.log4j.core.appender.ConsoleAppender)
+ {
+ loggerToHack.removeAppender(appender);
+ }
+ }
+ }
+ } catch (Throwable e) {
+ System.out.println("[Crucible] Unable to hack other loggers, expect broken and chaotic logs.");
+ e.printStackTrace();
+ }
+ // Crucible end
+
+ CrucibleServerMainHook.restoreStreams(); // Crucible - Restores the original streams so System.out does not log to forge logger
+ new Thread(new TerminalConsoleWriterThread(System.out, this.reader)).start();
+ System.setOut(new PrintStream(new CrucibleTracingLoggerOutputStream(LogManager.getLogger("STDOUT"), Level.INFO), true));
+ System.setErr(new PrintStream(new CrucibleTracingLoggerOutputStream(LogManager.getLogger("STDERR"), Level.WARN), true));
+ // CraftBukkit end
field_155771_h.info("Starting minecraft server version 1.7.10");

if (Runtime.getRuntime().maxMemory() / 1024L / 1024L < 512L)
@@ -117,7 +206,7 @@
@@ -117,7 +158,7 @@
FMLCommonHandler.instance().onServerStart(this);

field_155771_h.info("Loading properties");
Expand All @@ -196,7 +148,7 @@
this.field_154332_n = new ServerEula(new File("eula.txt"));

if (!this.field_154332_n.func_154346_a())
@@ -172,6 +261,18 @@
@@ -172,6 +213,18 @@
this.setServerPort(this.settings.getIntProperty("server-port", 25565));
}

Expand All @@ -215,7 +167,7 @@
field_155771_h.info("Generating keypair");
this.setKeyPair(CryptManager.createNewKeyPair());
field_155771_h.info("Starting Minecraft server on " + (this.getServerHostname().length() == 0 ? "*" : this.getServerHostname()) + ":" + this.getServerPort());
@@ -180,7 +281,7 @@
@@ -180,7 +233,7 @@
{
this.func_147137_ag().addLanEndpoint(inetaddress, this.getServerPort());
}
Expand All @@ -224,7 +176,7 @@
{
field_155771_h.warn("**** FAILED TO BIND TO PORT!");
field_155771_h.warn("The exception was: {}", new Object[] {ioexception.toString()});
@@ -196,10 +297,17 @@
@@ -196,10 +249,17 @@
field_155771_h.warn("To change this, set \"online-mode\" to \"true\" in the server.properties file.");
}

Expand All @@ -244,7 +196,7 @@

if (!PreYggdrasilConverter.func_152714_a(this.settings))
{
@@ -208,7 +316,8 @@
@@ -208,7 +268,8 @@
else
{
FMLCommonHandler.instance().onServerStarted();
Expand All @@ -254,7 +206,7 @@
long j = System.nanoTime();

if (this.getFolderName() == null)
@@ -274,11 +383,30 @@
@@ -274,11 +335,30 @@
this.theRConThreadMain.startThread();
}

Expand Down Expand Up @@ -285,7 +237,7 @@
public boolean canStructuresSpawn()
{
return this.canSpawnStructures;
@@ -364,11 +492,19 @@
@@ -364,11 +444,19 @@

public void executePendingCommands()
{
Expand Down
49 changes: 33 additions & 16 deletions patches/org/bukkit/plugin/PluginLogger.java.patch
Original file line number Diff line number Diff line change
@@ -1,25 +1,42 @@
--- ../src-base/minecraft/org/bukkit/plugin/PluginLogger.java
+++ ../src-work/minecraft/org/bukkit/plugin/PluginLogger.java
@@ -22,14 +22,20 @@
@@ -1,5 +1,7 @@
package org.bukkit.plugin;

+import io.github.crucible.JulLogManager;
+
import java.util.logging.Level;
import java.util.logging.LogRecord;
import java.util.logging.Logger;
@@ -11,8 +13,7 @@
*
* @see Logger
*/
-public class PluginLogger extends Logger {
- private String pluginName;
+public class PluginLogger extends JulLogManager.JulToLog4jLogger {

/**
* Creates a new PluginLogger that extracts the name from a plugin.
@@ -20,17 +21,12 @@
* @param context A reference to the plugin
*/
public PluginLogger(Plugin context) {
super(context.getClass().getCanonicalName(), null);
String prefix = context.getDescription().getPrefix();
- super(context.getClass().getCanonicalName(), null);
- String prefix = context.getDescription().getPrefix();
- pluginName = prefix != null ? new StringBuilder().append("[").append(prefix).append("] ").toString() : "[" + context.getDescription().getName() + "] ";
+ // Crucible start - give plugins a proper prefix for log4j
+ //pluginName = prefix != null ? new StringBuilder().append("[").append(prefix).append("] ").toString() : "[" + context.getDescription().getName() + "] ";
+ pluginName = prefix != null ? prefix : context.getDescription().getName();
+ // Crucible end
setParent(context.getServer().getLogger());
- setParent(context.getServer().getLogger());
+ super(getLoggerName(context));
setLevel(Level.ALL);
}

@Override
public void log(LogRecord logRecord) {
- @Override
- public void log(LogRecord logRecord) {
- logRecord.setMessage(pluginName + logRecord.getMessage());
+ // Crucible start - fix log4j prefix
+ //logRecord.setMessage(pluginName + logRecord.getMessage());
+ logRecord.setLoggerName(pluginName);
+ // Crucible end
super.log(logRecord);
- super.log(logRecord);
+ private static String getLoggerName(Plugin context) {
+ String prefix = context.getDescription().getPrefix();
+ return prefix != null ? prefix : context.getDescription().getName();
}

-
}
Loading
Loading