Make console log handler obey Filters. Closes #866
This commit is contained in:
parent
df82720ade
commit
224db6596e
@ -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 ) );
|
||||
}
|
||||
}
|
||||
|
@ -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<ChatColor, String> 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
|
||||
{
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user