mirror of
https://github.com/PaperMC/Paper.git
synced 2024-11-03 01:10:37 +01:00
Add log filtering!
This commit is contained in:
parent
427d6df4cb
commit
c6e50618a8
77
CraftBukkit-Patches/0055-Add-Log-Filtering.patch
Normal file
77
CraftBukkit-Patches/0055-Add-Log-Filtering.patch
Normal file
@ -0,0 +1,77 @@
|
|||||||
|
From a6d06947f8a021fe637a3a32b1c1e5a8213ffc93 Mon Sep 17 00:00:00 2001
|
||||||
|
From: md_5 <md_5@live.com.au>
|
||||||
|
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..fd26480
|
||||||
|
--- /dev/null
|
||||||
|
+++ b/src/main/java/org/spigotmc/LogFilter.java
|
||||||
|
@@ -0,0 +1,21 @@
|
||||||
|
+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)
|
||||||
|
+ {
|
||||||
|
+ 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 67854aa..7c80298 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;
|
||||||
|
@@ -238,4 +240,27 @@ public class SpigotConfig
|
||||||
|
whitelistMessage = transform( getString( "messages.whitelist", "You are not whitelisted on this server!" ) );
|
||||||
|
unknownCommandMessage = transform( getString( "messages.unknown-command", "Unknown command. Type \"help\" for help." ) );
|
||||||
|
}
|
||||||
|
+
|
||||||
|
+ public static List<Pattern> logFilters;
|
||||||
|
+ private static void filters()
|
||||||
|
+ {
|
||||||
|
+ List<String> def = Arrays.asList( new String[]
|
||||||
|
+ {
|
||||||
|
+ "^(.*)(/login)(.*)$"
|
||||||
|
+ } );
|
||||||
|
+ logFilters = new ArrayList<Pattern>();
|
||||||
|
+
|
||||||
|
+ for ( String regex : (List<String>) 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
|
||||||
|
|
Loading…
Reference in New Issue
Block a user