From 625a88686e7b0a6f24c79b5ae777d02a32e9cbcd Mon Sep 17 00:00:00 2001 From: md_5 Date: Sat, 22 Jun 2013 16:40:11 +1000 Subject: [PATCH] Add Log Filtering diff --git a/src/main/java/org/spigotmc/LogFilter.java b/src/main/java/org/spigotmc/LogFilter.java new file mode 100644 index 0000000..aa7e9ab --- /dev/null +++ b/src/main/java/org/spigotmc/LogFilter.java @@ -0,0 +1,24 @@ +package org.spigotmc; + +import java.util.logging.Filter; +import java.util.logging.LogRecord; +import java.util.regex.Pattern; + +public class LogFilter implements Filter +{ + + public boolean isLoggable(LogRecord record) + { + if ( record.getMessage() != null ) + { + for ( Pattern pattern : SpigotConfig.logFilters ) + { + if ( pattern.matcher( record.getMessage() ).matches() ) + { + return false; + } + } + } + return true; + } +} diff --git a/src/main/java/org/spigotmc/SpigotConfig.java b/src/main/java/org/spigotmc/SpigotConfig.java index d2058f3..e8039d7 100644 --- a/src/main/java/org/spigotmc/SpigotConfig.java +++ b/src/main/java/org/spigotmc/SpigotConfig.java @@ -13,6 +13,8 @@ import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.logging.Level; +import java.util.regex.Pattern; +import java.util.regex.PatternSyntaxException; import net.minecraft.server.MinecraftServer; import org.bukkit.Bukkit; import org.bukkit.ChatColor; @@ -255,4 +257,27 @@ public class SpigotConfig unknownCommandMessage = transform( getString( "messages.unknown-command", "Unknown command. Type \"help\" for help." ) ); serverFullMessage = transform( getString( "messages.server-full", "The server is full!" ) ); } + + public static List logFilters; + private static void filters() + { + List def = Arrays.asList( new String[] + { + "^(.*)(/login)(.*)$" + } ); + logFilters = new ArrayList(); + + for ( String regex : (List) getList( "settings.log-filters", def ) ) + { + try + { + logFilters.add( Pattern.compile( regex ) ); + } catch ( PatternSyntaxException ex ) + { + Bukkit.getLogger().log( Level.WARNING, "Supplied filter " + regex + " is invalid, ignoring!", ex ); + } + } + + Bukkit.getLogger().setFilter( new LogFilter() ); + } } -- 1.8.1.2