summaryrefslogtreecommitdiff
path: root/filters/minecraft.py
diff options
context:
space:
mode:
authorauric <auric@japegames.com>2026-02-22 19:13:06 -0600
committerauric <auric@japegames.com>2026-02-22 19:13:06 -0600
commit23527346905a2728c418170a155d0c24b10f5b25 (patch)
tree5edac5323122cf42b9a1ba5de83e58143b01fe4e /filters/minecraft.py
parentf0baf8f2f3778d21692d377d32bd4e372cef2aae (diff)
Add log_filter: pluggable per-unit output filter subprocess
Each unit can specify log_filter: <path> pointing to any executable that reads stdin and writes filtered output to stdout. The daemon spawns it once at startup (and on SIGHUP), pipes raw log data through it before ring-buffering and broadcasting to attached clients. filter.c handles spawn (fork/exec with pipes), per-chunk apply (write + poll with 250ms timeout, pass-through on silence/timeout), and stop (SIGTERM + fd cleanup). Filters are stopped and restarted cleanly on SIGHUP alongside log_tail. Bundled filters in filters/: source.py — TF2, GMod: strips server_cvar/stuck/path_goal spam, strips the L MM/DD/YYYY - HH:MM:SS: prefix minecraft.py — vanilla/Paper/Spigot: strips keepAlive, autosave, internal class logs, strips [HH:MM:SS] [thread] prefix terraria.py — vanilla/tModLoader: strips blank lines and mod loading noise during startup Any executable reading stdin/writing stdout works as a custom filter. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Diffstat (limited to 'filters/minecraft.py')
-rw-r--r--filters/minecraft.py45
1 files changed, 45 insertions, 0 deletions
diff --git a/filters/minecraft.py b/filters/minecraft.py
new file mode 100644
index 0000000..d4112d6
--- /dev/null
+++ b/filters/minecraft.py
@@ -0,0 +1,45 @@
+#!/usr/bin/env python3
+"""
+Minecraft log filter for Umbrella (vanilla, Paper, Spigot, Fabric, etc.)
+
+Strips low-value noise:
+ - keepAlive packet spam (Paper/Spigot debug logs)
+ - Internal class/library log lines
+ - Advancement grant/revoke noise
+ - Saving chunks / autosave lines
+ - UUID cache loading lines
+
+Strips the "[HH:MM:SS] [Thread/LEVEL]: " prefix from standard Minecraft
+log format, since the daemon already timestamps output.
+
+Install: /usr/lib/umbrella/filters/minecraft.py
+Unit YAML: log_filter: /usr/lib/umbrella/filters/minecraft.py
+"""
+
+import sys
+import re
+
+# Standard Minecraft log prefix: [HH:MM:SS] [Server thread/INFO]:
+PREFIX = re.compile(r'^\[\d{2}:\d{2}:\d{2}\] \[[^\]]+\]: ')
+
+SKIP = re.compile(
+ r'keepAlive' # packet keepAlive debug
+ r'|Saving chunks for level' # periodic autosave
+ r'|Saving and pausing game'
+ r'|com\.mojang\.' # internal Mojang class logs
+ r'|RCON Client /' # RCON connection noise
+ r'|RCON Listener'
+ r'|Preparing spawn area'
+ r'|Loading libraries'
+ r'|Loaded \d+ recipes'
+ r'|Loaded \d+ advancements'
+ r'|\[uuid-cache\]'
+ r'|^\s*$'
+)
+
+for line in sys.stdin:
+ if SKIP.search(line):
+ continue
+ line = PREFIX.sub('', line)
+ sys.stdout.write(line)
+ sys.stdout.flush()