Add the Server Log window

Tools > Server Log (Ctrl+Shift+L), offered with b_virtualserver_log_view,
reads the virtual server's log with logview, a hundred lines at a time,
with Show Older going further back. As in TS3, lines can be narrowed by
level, left out by exclude terms, coloured by keyword, and shown in UTC
or local time; the choices are kept in the settings. The find bar, with
its show-only-matches toggle, takes the place of TS3's separate search
and filter fields.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-10-04 13:19:52 +00:00
co-authored by Claude Opus 5.5
parent fb1de8ac5b
commit 8255d986ac
18 changed files with 1190 additions and 6 deletions
@@ -0,0 +1,77 @@
package com.ts3client.config;
import com.ts3client.config.ServerLogSettings.Highlight;
import com.ts3client.net.ServerLogEntry.Level;
import org.junit.jupiter.api.Test;
import java.util.List;
import java.util.Properties;
import java.util.Set;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertNull;
import static org.junit.jupiter.api.Assertions.assertTrue;
class ServerLogSettingsTest {
@Test
void whatIsStoredLoadsBack() {
ServerLogSettings saved = new ServerLogSettings();
saved.levels.remove(Level.INFO);
saved.localTime = true;
saved.highlights.clear();
saved.highlights.add(new Highlight("banned", 0x112233, null));
saved.highlights.add(new Highlight("kicked", null, 0xABCDEF));
saved.excludes.add("ping timeout");
Properties p = new Properties();
saved.store(p);
ServerLogSettings loaded = new ServerLogSettings();
loaded.load(p);
assertEquals(Set.of(Level.CRITICAL, Level.ERROR, Level.WARNING), loaded.levels);
assertTrue(loaded.localTime);
assertEquals(saved.highlights, loaded.highlights);
assertEquals(List.of("ping timeout"), loaded.excludes);
}
@Test
void shorterListsLeaveNoStaleEntriesBehind() {
ServerLogSettings s = new ServerLogSettings();
s.excludes.addAll(List.of("a", "b", "c"));
Properties p = new Properties();
s.store(p);
s.excludes.clear();
s.highlights.clear();
s.store(p);
assertTrue(p.stringPropertyNames().stream().noneMatch(k -> k.startsWith("serverLog.exclude.")));
assertTrue(p.stringPropertyNames().stream().noneMatch(k -> k.startsWith("serverLog.highlight.")));
ServerLogSettings loaded = new ServerLogSettings();
loaded.load(p);
assertTrue(loaded.excludes.isEmpty());
assertTrue(loaded.highlights.isEmpty());
}
@Test
void levelsAndExcludesDecideWhatShows() {
ServerLogSettings s = new ServerLogSettings();
s.levels.remove(Level.INFO);
s.excludes.add("Ping Timeout");
assertFalse(s.shows(Level.INFO, "client connected"));
assertTrue(s.shows(Level.WARNING, "something odd"));
assertFalse(s.shows(Level.WARNING, "dropping client because of ping timeout"));
assertTrue(s.shows(Level.DEBUG, "levels the window has no box for always show"));
}
@Test
void theFirstMatchingKeywordWins() {
ServerLogSettings s = new ServerLogSettings();
s.highlights.clear();
s.highlights.add(new Highlight("error", 1, null));
s.highlights.add(new Highlight("client", 2, null));
assertEquals(1, s.highlightFor("ERROR client gone").foreground());
assertEquals(2, s.highlightFor("client joined").foreground());
assertNull(s.highlightFor("nothing here"));
}
}
@@ -0,0 +1,39 @@
package com.ts3client.net;
import com.ts3client.net.ServerLogEntry.Level;
import org.junit.jupiter.api.Test;
import java.time.LocalDateTime;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNull;
class ServerLogEntryTest {
@Test
void readsTheServersLineFormat() {
ServerLogEntry e = ServerLogEntry.parse("2026-10-04 13:11:01.038554|WARNING |VirtualServer |1 |"
+ "client 'a|b'(id:19) was added to servergroup 'Server Admin'(id:6)");
assertEquals(LocalDateTime.of(2026, 10, 4, 13, 11, 1, 38_554_000), e.timestamp());
assertEquals(Level.WARNING, e.level());
assertEquals("VirtualServer", e.channel());
assertEquals("client 'a|b'(id:19) was added to servergroup 'Server Admin'(id:6)", e.message());
}
@Test
void keepsTheRestOfALineWithACutOffTimestamp() {
ServerLogEntry e = ServerLogEntry.parse("6-10-01 23:26:51.007742|INFO |VirtualServerBase|1 |listening on 0.0.0.0:9990");
assertNull(e.timestamp());
assertEquals(Level.INFO, e.level());
assertEquals("VirtualServerBase", e.channel());
assertEquals("listening on 0.0.0.0:9990", e.message());
}
@Test
void keepsAnUnreadableLineWhole() {
ServerLogEntry e = ServerLogEntry.parse("2026-10-04 00:23:41.975519|INFO ");
assertNull(e.timestamp());
assertEquals(Level.INFO, e.level());
assertEquals("2026-10-04 00:23:41.975519|INFO ", e.message());
}
}