diff --git a/src/logging.ts b/src/logging.ts index 9651e0cf2..28d8902bc 100644 --- a/src/logging.ts +++ b/src/logging.ts @@ -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, diff --git a/src/logging/console-prefix.test.ts b/src/logging/console-prefix.test.ts index dbb62a5eb..043e91281 100644 --- a/src/logging/console-prefix.test.ts +++ b/src/logging/console-prefix.test.ts @@ -9,6 +9,12 @@ describe("stripRedundantSubsystemPrefixForConsole", () => { ).toBe("hello"); }); + it("drops ':' prefix case-insensitively", () => { + expect( + stripRedundantSubsystemPrefixForConsole("WhatsApp: hello", "whatsapp"), + ).toBe("hello"); + }); + it("drops ' ' 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"),