From 224db6596eccff082c2c3f80eaddc60f9df647cc Mon Sep 17 00:00:00 2001 From: md_5 Date: Tue, 4 Feb 2014 16:44:53 +1100 Subject: [PATCH] Make console log handler obey Filters. Closes #866 --- .../net/md_5/bungee/log/BungeeLogger.java | 15 +++++++------ .../net/md_5/bungee/log/ColouredWriter.java | 21 ++++++++++++++++++- 2 files changed, 27 insertions(+), 9 deletions(-) diff --git a/proxy/src/main/java/net/md_5/bungee/log/BungeeLogger.java b/proxy/src/main/java/net/md_5/bungee/log/BungeeLogger.java index fa8c508cb..7f4ba6f4a 100644 --- a/proxy/src/main/java/net/md_5/bungee/log/BungeeLogger.java +++ b/proxy/src/main/java/net/md_5/bungee/log/BungeeLogger.java @@ -10,22 +10,22 @@ import net.md_5.bungee.BungeeCord; public class BungeeLogger extends Logger { - private final BungeeCord bungee; - private final ColouredWriter writer; private final Formatter formatter = new ConciseFormatter(); private final LogDispatcher dispatcher = new LogDispatcher( this ); public BungeeLogger(BungeeCord bungee) { super( "BungeeCord", null ); - this.bungee = bungee; - this.writer = new ColouredWriter( bungee.getConsoleReader() ); try { - FileHandler handler = new FileHandler( "proxy.log", 1 << 24, 8, true ); - handler.setFormatter( formatter ); - addHandler( handler ); + FileHandler fileHandler = new FileHandler( "proxy.log", 1 << 24, 8, true ); + fileHandler.setFormatter( formatter ); + addHandler( fileHandler ); + + ColouredWriter consoleHandler = new ColouredWriter( bungee.getConsoleReader() ); + consoleHandler.setFormatter( formatter ); + addHandler( consoleHandler ); } catch ( IOException ex ) { System.err.println( "Could not register logger!" ); @@ -43,6 +43,5 @@ public class BungeeLogger extends Logger void doLog(LogRecord record) { super.log( record ); - writer.print( formatter.format( record ) ); } } diff --git a/proxy/src/main/java/net/md_5/bungee/log/ColouredWriter.java b/proxy/src/main/java/net/md_5/bungee/log/ColouredWriter.java index 9d2ead4da..b3303ac19 100644 --- a/proxy/src/main/java/net/md_5/bungee/log/ColouredWriter.java +++ b/proxy/src/main/java/net/md_5/bungee/log/ColouredWriter.java @@ -3,11 +3,13 @@ package net.md_5.bungee.log; import java.io.IOException; import java.util.EnumMap; import java.util.Map; +import java.util.logging.Handler; +import java.util.logging.LogRecord; import jline.console.ConsoleReader; import net.md_5.bungee.api.ChatColor; import org.fusesource.jansi.Ansi; -public class ColouredWriter +public class ColouredWriter extends Handler { private final Map replacements = new EnumMap<>( ChatColor.class ); @@ -57,4 +59,21 @@ public class ColouredWriter { } } + + @Override + public void publish(LogRecord record) + { + print( getFormatter().format( record ) ); + } + + @Override + public void flush() + { + } + + @Override + public void close() throws SecurityException + { + } + }