chore(logging): strip redundant provider tags
This commit is contained in:
@@ -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,
|
||||
|
||||
@@ -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"),
|
||||
|
||||
Reference in New Issue
Block a user