summaryrefslogtreecommitdiff
path: root/filters/minecraft.py
blob: d4112d6e665cf95b7a74449f863febe883ae38e2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
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()