chore(logging): strip redundant provider tags

This commit is contained in:
Peter Steinberger
2026-01-13 04:35:48 +00:00
parent 62bdbe1821
commit ccc24e2c26
2 changed files with 31 additions and 1 deletions

View File

@@ -475,7 +475,22 @@ export function stripRedundantSubsystemPrefixForConsole(
displaySubsystem: string,
): string {
if (!displaySubsystem) return message;
if (!message.startsWith(displaySubsystem)) return message;
// Common duplication: "[discord] discord: ..." (when a message manually includes the subsystem tag).
if (message.startsWith("[")) {
const closeIdx = message.indexOf("]");
if (closeIdx > 1) {
const bracketTag = message.slice(1, closeIdx);
if (bracketTag.toLowerCase() === displaySubsystem.toLowerCase()) {
let i = closeIdx + 1;
while (message[i] === " ") i += 1;
return message.slice(i);
}
}
}
const prefix = message.slice(0, displaySubsystem.length);
if (prefix.toLowerCase() !== displaySubsystem.toLowerCase()) return message;
const next = message.slice(
displaySubsystem.length,

View File

@@ -9,6 +9,12 @@ describe("stripRedundantSubsystemPrefixForConsole", () => {
).toBe("hello");
});
it("drops '<Subsystem>:' prefix case-insensitively", () => {
expect(
stripRedundantSubsystemPrefixForConsole("WhatsApp: hello", "whatsapp"),
).toBe("hello");
});
it("drops '<subsystem> ' prefix", () => {
expect(
stripRedundantSubsystemPrefixForConsole(
@@ -18,6 +24,15 @@ describe("stripRedundantSubsystemPrefixForConsole", () => {
).toBe("gateway: closed");
});
it("drops '[subsystem]' prefix", () => {
expect(
stripRedundantSubsystemPrefixForConsole(
"[discord] connection stalled",
"discord",
),
).toBe("connection stalled");
});
it("keeps messages that do not start with the subsystem", () => {
expect(
stripRedundantSubsystemPrefixForConsole("discordant: hello", "discord"),