From eca99576a0bf41a07684fc653405b9e9d2a09111 Mon Sep 17 00:00:00 2001 From: md_5 Date: Mon, 11 Jul 2016 11:04:58 +1000 Subject: [PATCH] Move net.md_5.bungee.log to its own module. API subject to change and should not be used externally. --- log/nb-configuration.xml | 31 ++++++++++++++++ log/pom.xml | 35 +++++++++++++++++++ .../net/md_5/bungee/log/BungeeLogger.java | 11 +++--- .../net/md_5/bungee/log/ColouredWriter.java | 1 - .../net/md_5/bungee/log/ConciseFormatter.java | 1 + .../net/md_5/bungee/log/LogDispatcher.java | 0 .../md_5/bungee/log/LoggingOutputStream.java | 0 pom.xml | 1 + proxy/pom.xml | 8 ++--- .../main/java/net/md_5/bungee/BungeeCord.java | 2 +- 10 files changed, 79 insertions(+), 11 deletions(-) create mode 100644 log/nb-configuration.xml create mode 100644 log/pom.xml rename {proxy => log}/src/main/java/net/md_5/bungee/log/BungeeLogger.java (84%) rename {proxy => log}/src/main/java/net/md_5/bungee/log/ColouredWriter.java (99%) rename {proxy => log}/src/main/java/net/md_5/bungee/log/ConciseFormatter.java (99%) rename {proxy => log}/src/main/java/net/md_5/bungee/log/LogDispatcher.java (100%) rename {proxy => log}/src/main/java/net/md_5/bungee/log/LoggingOutputStream.java (100%) diff --git a/log/nb-configuration.xml b/log/nb-configuration.xml new file mode 100644 index 00000000..7e465924 --- /dev/null +++ b/log/nb-configuration.xml @@ -0,0 +1,31 @@ + + + + + + project + NEW_LINE + NEW_LINE + NEW_LINE + true + true + true + true + true + true + true + true + true + true + + diff --git a/log/pom.xml b/log/pom.xml new file mode 100644 index 00000000..28b20bd9 --- /dev/null +++ b/log/pom.xml @@ -0,0 +1,35 @@ + + + 4.0.0 + + + net.md-5 + bungeecord-parent + 1.10-SNAPSHOT + ../pom.xml + + + net.md-5 + bungeecord-log + 1.10-SNAPSHOT + jar + + BungeeCord-Log + Simplistic and performant java.util.Logger based logger and console API designed for use with BungeeCord and Minecraft related applications. + + + + jline + jline + 2.14.2 + compile + + + net.md-5 + bungeecord-chat + ${project.version} + compile + + + diff --git a/proxy/src/main/java/net/md_5/bungee/log/BungeeLogger.java b/log/src/main/java/net/md_5/bungee/log/BungeeLogger.java similarity index 84% rename from proxy/src/main/java/net/md_5/bungee/log/BungeeLogger.java rename to log/src/main/java/net/md_5/bungee/log/BungeeLogger.java index 94e924b6..9598fff3 100644 --- a/proxy/src/main/java/net/md_5/bungee/log/BungeeLogger.java +++ b/log/src/main/java/net/md_5/bungee/log/BungeeLogger.java @@ -7,7 +7,7 @@ import java.util.logging.Formatter; import java.util.logging.Level; import java.util.logging.LogRecord; import java.util.logging.Logger; -import net.md_5.bungee.BungeeCord; +import jline.console.ConsoleReader; public class BungeeLogger extends Logger { @@ -20,18 +20,18 @@ public class BungeeLogger extends Logger "CallToPrintStackTrace", "CallToThreadStartDuringObjectConstruction" }) @SuppressFBWarnings("SC_START_IN_CTOR") - public BungeeLogger(BungeeCord bungee) + public BungeeLogger(String loggerName, String filePattern, ConsoleReader reader) { - super( "BungeeCord", null ); + super( loggerName, null ); setLevel( Level.ALL ); try { - FileHandler fileHandler = new FileHandler( "proxy.log", 1 << 24, 8, true ); + FileHandler fileHandler = new FileHandler( filePattern, 1 << 24, 8, true ); fileHandler.setFormatter( formatter ); addHandler( fileHandler ); - ColouredWriter consoleHandler = new ColouredWriter( bungee.getConsoleReader() ); + ColouredWriter consoleHandler = new ColouredWriter( reader ); consoleHandler.setLevel( Level.INFO ); consoleHandler.setFormatter( formatter ); addHandler( consoleHandler ); @@ -40,6 +40,7 @@ public class BungeeLogger extends Logger System.err.println( "Could not register logger!" ); ex.printStackTrace(); } + dispatcher.start(); } diff --git a/proxy/src/main/java/net/md_5/bungee/log/ColouredWriter.java b/log/src/main/java/net/md_5/bungee/log/ColouredWriter.java similarity index 99% rename from proxy/src/main/java/net/md_5/bungee/log/ColouredWriter.java rename to log/src/main/java/net/md_5/bungee/log/ColouredWriter.java index 3a234e62..e7650f70 100644 --- a/proxy/src/main/java/net/md_5/bungee/log/ColouredWriter.java +++ b/log/src/main/java/net/md_5/bungee/log/ColouredWriter.java @@ -79,5 +79,4 @@ public class ColouredWriter extends Handler public void close() throws SecurityException { } - } diff --git a/proxy/src/main/java/net/md_5/bungee/log/ConciseFormatter.java b/log/src/main/java/net/md_5/bungee/log/ConciseFormatter.java similarity index 99% rename from proxy/src/main/java/net/md_5/bungee/log/ConciseFormatter.java rename to log/src/main/java/net/md_5/bungee/log/ConciseFormatter.java index 015a4716..61fdd281 100644 --- a/proxy/src/main/java/net/md_5/bungee/log/ConciseFormatter.java +++ b/log/src/main/java/net/md_5/bungee/log/ConciseFormatter.java @@ -24,6 +24,7 @@ public class ConciseFormatter extends Formatter formatted.append( "] " ); formatted.append( formatMessage( record ) ); formatted.append( '\n' ); + if ( record.getThrown() != null ) { StringWriter writer = new StringWriter(); diff --git a/proxy/src/main/java/net/md_5/bungee/log/LogDispatcher.java b/log/src/main/java/net/md_5/bungee/log/LogDispatcher.java similarity index 100% rename from proxy/src/main/java/net/md_5/bungee/log/LogDispatcher.java rename to log/src/main/java/net/md_5/bungee/log/LogDispatcher.java diff --git a/proxy/src/main/java/net/md_5/bungee/log/LoggingOutputStream.java b/log/src/main/java/net/md_5/bungee/log/LoggingOutputStream.java similarity index 100% rename from proxy/src/main/java/net/md_5/bungee/log/LoggingOutputStream.java rename to log/src/main/java/net/md_5/bungee/log/LoggingOutputStream.java diff --git a/pom.xml b/pom.xml index 299f6fa2..5897369a 100644 --- a/pom.xml +++ b/pom.xml @@ -42,6 +42,7 @@ chat config event + log module protocol proxy diff --git a/proxy/pom.xml b/proxy/pom.xml index 700e3278..55bba906 100644 --- a/proxy/pom.xml +++ b/proxy/pom.xml @@ -33,14 +33,14 @@ compile - jline - jline - 2.12 + net.md-5 + bungeecord-api + ${project.version} compile net.md-5 - bungeecord-api + bungeecord-log ${project.version} compile diff --git a/proxy/src/main/java/net/md_5/bungee/BungeeCord.java b/proxy/src/main/java/net/md_5/bungee/BungeeCord.java index ac08d8ee..9825b993 100644 --- a/proxy/src/main/java/net/md_5/bungee/BungeeCord.java +++ b/proxy/src/main/java/net/md_5/bungee/BungeeCord.java @@ -206,7 +206,7 @@ public class BungeeCord extends ProxyServer consoleReader = new ConsoleReader(); consoleReader.setExpandEvents( false ); - logger = new BungeeLogger( this ); + logger = new BungeeLogger( "BungeeCord", "proxy.log", consoleReader ); System.setErr( new PrintStream( new LoggingOutputStream( logger, Level.SEVERE ), true ) ); System.setOut( new PrintStream( new LoggingOutputStream( logger, Level.INFO ), true ) );