fix: restore Matrix quiet SDK logging

This commit is contained in:
Gustavo Madeira Santana
2026-04-22 20:42:52 -04:00
parent a0a927ddb0
commit 0520aeb244
3 changed files with 79 additions and 3 deletions

View File

@@ -218,6 +218,8 @@ Docs: https://docs.openclaw.ai
- Codex harness/hooks: fire `llm_input`, `llm_output`, and `agent_end` for native Codex app-server turns so lifecycle hooks stop drifting from Pi. Thanks @vincentkoc.
- QA/Telegram: record per-scenario reply RTT in the live Telegram QA report and summary, starting with the canary response. (#70550) Thanks @obviyus.
- Status: add an explicit `Runner:` field to `/status` so sessions now report whether they are running on embedded Pi, a CLI-backed provider, or an ACP harness agent/backend such as `codex (acp/acpx)` or `gemini (acp/acpx)`. (#70595)
- Gateway/diagnostics: enable payload-free stability recording by default and add a support-ready diagnostics export with sanitized logs, status, health, config, and stability snapshots for bug reports. (#70324) Thanks @gumadeiras.
- Matrix: require full cross-signing identity trust for self-device verification and add `openclaw matrix verify self` so operators can establish that trust from the CLI. (#70401) Thanks @gumadeiras.
### Fixes

View File

@@ -0,0 +1,30 @@
import { logger as matrixJsSdkLogger } from "matrix-js-sdk/lib/logger.js";
import { afterEach, describe, expect, it, vi } from "vitest";
import { LogService } from "../sdk/logger.js";
import {
createMatrixJsSdkClientLogger,
ensureMatrixSdkLoggingConfigured,
setMatrixSdkConsoleLogging,
setMatrixSdkLogMode,
} from "./logging.js";
describe("Matrix SDK logging", () => {
afterEach(() => {
setMatrixSdkLogMode("default");
setMatrixSdkConsoleLogging(false);
vi.restoreAllMocks();
});
it("suppresses Matrix SDK client logs in quiet mode", () => {
setMatrixSdkConsoleLogging(true);
setMatrixSdkLogMode("quiet");
ensureMatrixSdkLoggingConfigured();
const info = vi.spyOn(console, "info").mockImplementation(() => {});
createMatrixJsSdkClientLogger("MatrixClient").info("should be quiet");
matrixJsSdkLogger.info("global logger should be quiet");
LogService.info("MatrixClient", "should also be quiet");
expect(info).not.toHaveBeenCalled();
});
});

View File

@@ -2,6 +2,7 @@ import { logger as matrixJsSdkLogger } from "matrix-js-sdk/lib/logger.js";
import { ConsoleLogger, LogService, setMatrixConsoleLogging } from "../sdk/logger.js";
let matrixSdkLoggingConfigured = false;
let matrixSdkLogMode: "default" | "quiet" = "default";
const matrixSdkBaseLogger = new ConsoleLogger();
type MatrixJsSdkLogger = {
@@ -32,7 +33,7 @@ export function ensureMatrixSdkLoggingConfigured(): void {
}
export function setMatrixSdkLogMode(mode: "default" | "quiet"): void {
void mode;
matrixSdkLogMode = mode;
if (!matrixSdkLoggingConfigured) {
return;
}
@@ -47,13 +48,42 @@ export function createMatrixJsSdkClientLogger(prefix = "matrix"): MatrixJsSdkLog
return createMatrixJsSdkLoggerInstance(prefix);
}
function shouldSuppressMatrixHttpNotFound(module: string, messageOrObject: unknown[]): boolean {
if (!module.includes("MatrixHttpClient")) {
return false;
}
return messageOrObject.some((entry) => {
if (!entry || typeof entry !== "object") {
return false;
}
return (entry as { errcode?: string }).errcode === "M_NOT_FOUND";
});
}
function applyMatrixSdkLogger(): void {
if (matrixSdkLogMode === "quiet") {
LogService.setLogger({
trace: () => {},
debug: () => {},
info: () => {},
warn: () => {},
error: () => {},
});
applyMatrixJsSdkLogger();
return;
}
LogService.setLogger({
trace: (module, ...messageOrObject) => matrixSdkBaseLogger.trace(module, ...messageOrObject),
debug: (module, ...messageOrObject) => matrixSdkBaseLogger.debug(module, ...messageOrObject),
info: (module, ...messageOrObject) => matrixSdkBaseLogger.info(module, ...messageOrObject),
warn: (module, ...messageOrObject) => matrixSdkBaseLogger.warn(module, ...messageOrObject),
error: (module, ...messageOrObject) => matrixSdkBaseLogger.error(module, ...messageOrObject),
error: (module, ...messageOrObject) => {
if (shouldSuppressMatrixHttpNotFound(module, messageOrObject)) {
return;
}
matrixSdkBaseLogger.error(module, ...messageOrObject);
},
});
applyMatrixJsSdkLogger();
}
@@ -78,6 +108,12 @@ function applyMatrixJsSdkLogger(): void {
const method = normalizeMatrixJsSdkLogMethod(methodName);
const module = formatMatrixJsSdkLoggerName(loggerName);
return (...messageOrObject) => {
if (matrixSdkLogMode === "quiet") {
return;
}
if (method === "error" && shouldSuppressMatrixHttpNotFound(module, messageOrObject)) {
return;
}
(matrixSdkBaseLogger[method] as (module: string, ...args: unknown[]) => void)(
module,
...messageOrObject,
@@ -90,6 +126,9 @@ function applyMatrixJsSdkLogger(): void {
function createMatrixJsSdkLoggerInstance(prefix: string): MatrixJsSdkLogger {
const log = (method: keyof ConsoleLogger, ...messageOrObject: unknown[]): void => {
if (matrixSdkLogMode === "quiet") {
return;
}
(matrixSdkBaseLogger[method] as (module: string, ...args: unknown[]) => void)(
prefix,
...messageOrObject,
@@ -101,7 +140,12 @@ function createMatrixJsSdkLoggerInstance(prefix: string): MatrixJsSdkLogger {
debug: (...messageOrObject) => log("debug", ...messageOrObject),
info: (...messageOrObject) => log("info", ...messageOrObject),
warn: (...messageOrObject) => log("warn", ...messageOrObject),
error: (...messageOrObject) => log("error", ...messageOrObject),
error: (...messageOrObject) => {
if (shouldSuppressMatrixHttpNotFound(prefix, messageOrObject)) {
return;
}
log("error", ...messageOrObject);
},
getChild: (namespace: string) => {
const nextNamespace = namespace.trim();
return createMatrixJsSdkLoggerInstance(nextNamespace ? `${prefix}.${nextNamespace}` : prefix);